List
1 type17 functionsFunctions on List(a), the singly linked list. A list literal [1, 2, 3] is
built from empty and cons, and a match takes one
apart with list patterns such as [x, ..rest]. Functions that could fail on
an empty list or a missing element answer a Result instead of trapping.
Types
Result
Shorthand for [Ok(a) | Err(e)], the variant this module's fallible
functions return.
Functions
empty
The empty list. A list literal is this and cons: [1, 2] is
cons(1, cons(2, empty())).
cons
The list with head in front of tail. A list literal is this and
empty: [1, 2] is cons(1, cons(2, empty())).
head
Total: an empty list is an Err rather than a trap.
tail
The tail of the empty list is the empty list.
length
The number of elements.
map
Each element passed through f, in order.
filter
The elements the predicate holds for, in their order.
foldl
foldl([x0, x1], init, f) is f(f(init, x0), x1).
forEach
map for a callback run only for what it does, building no list.
nth
Total: an index outside the list is an Err rather than a trap.
reverse
The elements in the opposite order.
concat
The elements of the first list, then those of the second.
flatMap
Each element's list from f, joined in order.
find
The first element the predicate holds for.
any
any([], p) is false.
all
all([], p) is true.
sort
A stable sort: elements the comparator calls equal keep their order. The comparator answers a sign, negative when its first argument goes first.