zena:iterator
import {…} from 'zena:iterator';
Interfaces
Iterator
interface Iterator<T>
A stateful iterator over elements of type T.
Usage pattern with let-pattern conditions:
let iter = collection.[Iterable.iterator]();
while (let (true, item) = iter.next()) {
// use item
}
Design: Uses inline tuple returns for zero-allocation iteration.
- next() returns inline (true, T) when there's an element
- next() returns inline (false, _) when exhausted
next(): inline (true, T) | inline (false, _)
Advances the iterator and returns the next element.
Returns inline (true, element) if there is an element,
inline (false, _) if exhausted.
Iterable
interface Iterable<T>
A collection that can produce an Iterator.
contains(value: T): boolean
Returns true if the collection contains the specified value.
all(predicate: (item: T) => boolean): boolean
Returns true if all elements match the given predicate. Returns true if the collection is empty.
some(predicate: (item: T) => boolean): boolean
Returns true if at least one element matches the given predicate. Returns false if the collection is empty.
fold<R>(initial: R, combine: (acc: R, item: T) => R): R
Reduces the collection to a single value by accumulating state.
find(predicate: (item: T) => boolean): inline (true, T) | inline (false, _)
Finds the first element that matches the predicate. Returns an inline tuple (true, item) if found, or (false, _) if not.
filter(predicate: (item: T) => boolean): Iterable<T>
Returns a new iterable containing only the elements that match the predicate.