std/list
Operations on the persistent linked List<'T> type. Container-specific ops
(concat, head, tail) live here; generic iteration — including
Iter.count (O(1) via the known_count protocol) — goes through the
iter module: Iter.map(xs, f) |> Iter.to_list() for the strict,
List-returning form.
Import with import std/list.
Exports
Section titled “Exports”Types
type List
Section titled “type List”type List<'T>
Ordered, immutable sequence of elements.
List.list_next
Section titled “List.list_next”fn list_next(list: List<'T>): Maybe<('T, List<'T>)>
type function on List
Returns the next element and remaining list, or None if empty. Drives the
Iter implementation for List. (Named list_next rather than
next so it doesn’t collide with the Iterable.next function on List.)
Interactive Tests
assert List.list_next([1, 2, 3]) == Some((1, [2, 3]))
assert List.list_next([]) == None
List.concat
Section titled “List.concat”fn concat(a: List<'T>, b: List<'T>): List<'T>
type function on List
Concatenates two lists, yielding all elements of a followed by all of b.
Interactive Tests
assert List.concat([1, 2], [3, 4]) == [1, 2, 3, 4]
List.head
Section titled “List.head”fn head(list: List<'T>): Maybe<'T>
type function on List
Returns the first element, or None if the list is empty. The cons-list
idiom, paired with tail; the stream-vocabulary equivalent is the free
function Iter.first.
Interactive Tests
assert List.head([1, 2, 3]) == Some(1)
assert List.head([]) == None
List.tail
Section titled “List.tail”fn tail(list: List<'T>): Maybe<List<'T>>
type function on List
Returns all elements except the first, or None if the list is empty.
Interactive Tests
assert List.tail([1, 2, 3]) == Some([2, 3])
assert List.tail([]) == None
List.next
Section titled “List.next”impl Iterable
fn next(list: List<'T>): Maybe<('T, List<'T>)>
impl Iterable.next
List.known_count
Section titled “List.known_count”impl Iterable
fn known_count(list: List<'T>): Maybe<Int>
impl Iterable.known_count
List.add
Section titled “List.add”impl Add
fn add(lhs: List<'T>, rhs: List<'T>): List<'T>
impl Add.add
List.to_string
Section titled “List.to_string”impl Display
fn to_string(value: List<'T>): String
impl Display.to_string
List.inspect
Section titled “List.inspect”impl Debug
fn inspect(value: List<'T>): String
impl Debug.inspect
List.equal?
Section titled “List.equal?”impl Equatable
fn equal?(a: List<'T>, b: List<'T>): Bool
impl Equatable.equal?
List.hash
Section titled “List.hash”impl Hashable
fn hash(list: List<'T>): Int
impl Hashable.hash
List.compare
Section titled “List.compare”impl Comparable
fn compare(a: List<'T>, b: List<'T>): Ordering
impl Comparable.compare