Skip to content

Lists

List<A> is an ordered, immutable list of values of type A. Use [] for an empty list and [head | tail] to prepend an element. Pattern matching separates the empty and non-empty cases:

mod lists
alias gale_std.list
pub fn prepend(value: Integer, values: List<Integer>) -> List<Integer> {
[value | values]
}
pub fn first(values: List<Integer>) -> Option<Integer> {
case values {
[] -> None
[head | _] -> Some(head)
}
}
pub fn double_positive(values: List<Integer>) -> List<Integer> {
values
|> list.filter(fn(value: Integer) -> value > 0)
|> list.map(fn(value: Integer) -> value * 2)
}

gale_std.list owns both structural operations such as first, length, and reverse and eager transformations such as map, filter, and reduce. Each operation returns a value; it does not change the original list. See the standard library for more operations.