Iterable
Iterable module: sequence operations over List(a).
This module provides a unified set of sequence operations: map, filter, fold, take, drop, zip, enumerate, flat_map, any, all, find, count.
All functions operate on List(a). When the runtime gains interface dispatch, these will be generalised to work over any type implementing Iterable(a).
The Iterable interface (future):
interface Iterable(a) do
fn next(self : Self) : Option((a, Self))
end
impl Iterable(a) for List(a) do
fn next(xs : List(a)) : Option((a, List(a))) do
match xs do
| Nil -> None
| Cons(h, t) -> Some((h, t))
end
end
endUntil then, every function here takes and returns List(a).
Functions
Returns true if all elements satisfy pred (short-circuits on failure).
Returns true if any element satisfies pred (short-circuits).
Returns the number of elements in the list.
Drops the first n elements. Returns [] if n >= length.
Pairs each element with its 0-based index: [a, b] -> [(0, a), (1, b)].
Returns only the elements for which pred returns true.
Returns the first element satisfying pred, or None.
Applies f to each element; collects the resulting lists and concatenates them.
Left fold: reduces the list from left to right using an accumulator. Argument order: collection first, init second, callback last (uncurried-collection convention). Callback f(acc, x) returns the new accumulator.
Applies f to each element, returning a new list of results.
Returns the first n elements. Returns the whole list if n >= length.
Pairs up elements from two lists. Stops at the shorter list.