Collections
Functions for working with collections and collection values.
count
1-parameter signature
count(collection)
Count returns the number of values in an iterable, including map values.
A measurable source supplies its length without traversal; computing that length
may still perform I/O. Negative measured lengths are rejected without traversal.
Otherwise one traversal may consume a one-shot source,
perform I/O, or never finish for an unbounded source. The acquired iterator is
closed; the source and its values remain borrowed. Traversal, cancellation,
overflow, and iterator close failures are returned without a partial count.
- Parameters
collectionIterableSource whose yielded values are counted.
- Returns
IntNumber of yielded values, or the source's measured length.
count_distinct
1-parameter signature
count_distinct(collection)
CountDistinct counts distinct yielded values using canonical runtime equality.
Maps contribute values, not keys. One traversal may consume a one-shot source,
perform I/O, or never finish for an unbounded source. The acquired iterator is
closed; the source and yielded values are neither cloned nor closed. Iteration,
equality, cancellation, and close failures are returned without a partial count.
- Parameters
collectionIterableSource whose distinct yielded values are counted.
- Returns
IntNumber of distinct yielded values.
includes
2-parameter signature
includes(haystack, needle)
Includes checks membership, preferring a host's Contains capability over a scan.
Strings convert the needle to text. Iterable scans compare yielded values,
including map values, using canonical equality and stop at the first match.
Only the acquired iterator is closed; traversal, equality, cancellation, and
close failures are preserved, including a close failure after a match.
Host capabilities receive the caller's context and own cancellation of their
blocking work. The scan does not independently poll cancellation.
- Parameters
haystackString | Containable | IterableThe value container.needleAnyThe target value to assert.
- Returns
BooleanA boolean value that indicates whether a container contains a given value.
reverse
1-parameter signature
reverse(value)
Reverse reverses Unicode code points in a string or indexed elements in a list.
Lists construct an independent outer list through New, preserving implementation
family and backend configuration. Elements remain shallow borrowed references.
Failed or canceled construction is handled by the factory; subsequent failures
close the incomplete destination and preserve cleanup errors. Success transfers
destination ownership to the caller. The source and its elements are not closed.
- Parameters
valueString | ListThe string or indexed list to reverse.
- Returns
String | ListA reversed string or new list of the source's implementation family.