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 end
Until then, every function here takes and returns List(a).
Functions
Applies f to each element, returning a new list of results.
Applies f to each element; collects the resulting lists and concatenates them.
Returns only the elements for which pred returns true.
Left fold: reduces the list from left to right using an accumulator. f is called as f(acc, x) returning the new accumulator.
Returns the number of elements in the list.
Returns true if any element satisfies pred (short-circuits).
Returns true if all elements satisfy pred (short-circuits on failure).
Returns the first element satisfying pred, or None.
Returns the first n elements. Returns the whole list if n >= length.
Drops the first n elements. Returns [] if n >= length.
Pairs up elements from two lists. Stops at the shorter list.
Pairs each element with its 0-based index: [a, b] -> [(0, a), (1, b)].