Skip to content

Collection

1 min read

No import is needed.

Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.

Collection

Sized collection — the type users pass into APIs that need a count. for (let x in xs) works for concrete @iterator types and for interface-typed Collection / IndexedCollection / Iterator (via .iterator() / .next() dispatch). Query chains start with seq() in system.collections, keeping bootstrap independent of List.

public interface Collection<T>: Iterable<T>

length

Number of elements currently stored.

get length(): int

is_empty

True when the collection has no elements.

public fun is_empty(): bool

all

True when every element satisfies pred.

public fun all(borrow pred: fun(T): bool): bool

any

True when at least one element satisfies pred.

public fun any(borrow pred: fun(T): bool): bool

none

True when no element satisfies pred.

public fun none(borrow pred: fun(T): bool): bool

count

Counts elements for which pred is true.

public fun count(borrow pred: fun(T): bool): int

find

First element for which pred is true, or None.

public fun find(borrow pred: fun(T): bool): Option<T>

for_each

Invokes action for each element in iteration order.

public fun for_each(borrow action: fun(T): void): void