List
Functions over R lists, typed list[T], and over Arrays. Each function
also takes an Array<T> as its collection (the list, first or lists argument) and then
returns an Array where it would return a list, so List.map([1, 2, 3], \(x) x * 2) is the
Array<double> [2, 4, 6]. An item argument does not count, so List.append(list([1]), [2]) is
the list list([1], [2]), and List.single and List.repeat always return lists. A function
whose result items come from a callback, such as List.map, requires them to be Array items (the
item constraint), so List.map([1, 2], \(x) list(x)) is
a type error.
| Function | Summary |
|---|---|
List.from_vector |
The elements of an atomic vector as a list. |
List.to_vector |
The elements of a list as an atomic vector; every element must be a scalar of one type. |
List.len |
The number of elements. |
List.is_empty |
Whether the list has no elements. |
List.get |
The element at a 1-based position, or :Err(:OutOfBounds). |
List.set |
Replaces the element at a position; a position out of range leaves the list unchanged. |
List.update |
Replaces the element at a position with f of it. |
List.append |
Adds an element at the end. |
List.prepend |
Adds an element at the start. |
List.concat |
The elements of first followed by those of second. |
List.single |
A list of one element. |
List.repeat |
A list of count copies of value. |
List.range |
The integers from start up to and including end, or an empty list when end is smaller. |
List.reverse |
The elements in reverse order. |
List.join |
Concatenates a list of lists. |
List.map |
Applies f to every element. |
List.map_with_index |
Applies f to every element and its 1-based position. |
List.map2 |
Applies f to the elements of two lists pairwise, stopping at the shorter one. |
List.map3 |
Applies f to the elements at each position of three lists, up to the shortest one. |
List.map4 |
Applies f to the elements at each position of four lists, up to the shortest one. |
List.join_map |
Applies f, which returns a list, to every element and concatenates the results. |
List.keep_if |
The elements for which predicate is TRUE. |
List.keep_if_try |
The elements for which predicate returns :Ok(TRUE), or the first :Err it returns. |
List.drop_if |
The elements for which predicate is FALSE. |
List.keep_oks |
Applies f to every element and keeps the :Ok values. |
List.keep_errs |
Applies f to every element and keeps the :Err values. |
List.map_try |
Applies f to every element and stops at the first :Err. |
List.walk |
Folds from the first element: f gets the state and an element and returns the next state. |
List.walk_backwards |
Folds from the last element. |
List.walk_until |
Folds until f returns :Break(state); :Continue(state) goes on. |
List.walk_backwards_until |
Folds the list from the last element until f returns :Break(state). |
List.walk_with_index |
Folds the list, passing f each element’s 1-based position too. |
List.walk_with_index_until |
Folds the list with positions until f returns :Break(state). |
List.walk_from |
Folds the list from a 1-based position onwards. |
List.walk_from_until |
Folds the list from a position until f returns :Break(state). |
List.walk_try |
Folds the list while f returns :Ok(state), stopping at the first :Err. |
List.for_each |
Calls f on each element for its effect, and returns NULL invisibly. |
List.for_each_try |
Calls f on each element, stopping at the first :Err. |
List.any |
Whether predicate is TRUE for some element. |
List.all |
Whether predicate is TRUE for every element; TRUE for an empty list. |
List.contains |
Whether some element is identical() to value. |
List.count_if |
The number of elements for which predicate is TRUE. |
List.find_first |
The first element for which predicate is TRUE, or :Err(:NotFound). |
List.find_last |
The last element for which predicate is TRUE, or :Err(:NotFound). |
List.find_first_index |
The position of the first match, or :Err(:NotFound). |
List.find_last_index |
The position of the last match, or :Err(:NotFound). |
List.first |
The first element, or :Err(:ListWasEmpty). |
List.last |
The last element, or :Err(:ListWasEmpty). |
List.take_first |
The first count elements, or all of them if there are fewer. |
List.take_last |
The last count elements. |
List.drop_first |
Everything but the first count elements. |
List.drop_last |
Everything but the last count elements. |
List.drop_at |
Removes the element at a position. |
List.sublist |
count elements starting at position start. |
List.split_at |
The first count elements as before and the rest as others. |
List.split_first |
Splits the list around the first element identical to delimiter. |
List.split_last |
Splits the list around the last element identical to delimiter. |
List.split_on |
The runs of elements between elements identical to delimiter. |
List.split_on_list |
The runs of elements between occurrences of the sublist delimiter. |
List.chunks_of |
Groups of size elements; the last group may be shorter. |
List.intersperse |
Puts separator between every two elements. |
List.sort_with |
A stable sort by compare, which returns :LT, :EQ or :GT. |
List.sort_asc |
Sorts numbers from smallest to largest. |
List.sort_desc |
Sorts numbers from largest to smallest. |
List.swap |
Exchanges the elements at two positions; an out-of-range position leaves the list unchanged. |
List.replace |
Replaces the element at a position, returning the new list and the element it replaced. |
List.append_if_ok |
Adds an :Ok value at the end; an :Err leaves the list unchanged. |
List.prepend_if_ok |
Adds an :Ok value at the start; an :Err leaves the list unchanged. |
List.concat_utf8 |
Appends the UTF-8 bytes of a string to a list of bytes. |
List.with_capacity |
An empty list with room for capacity elements, so appending that many never copies. |
List.reserve |
The list with room for spare more elements. |
List.release_excess_capacity |
The list with no room beyond its elements, which gives back what List.reserve or List.with_capacity set aside. |
List.sum |
The sum of the elements; 0L for an empty list. |
List.product |
The product of the elements; 1L for an empty list. |
List.min |
The smallest element, or :Err(:ListWasEmpty). |
List.max |
The largest element, or :Err(:ListWasEmpty). |
List.starts_with |
Whether the list begins with the elements of prefix. |
List.ends_with |
Whether the list ends with the elements of suffix. |
List.from_vector
Section titled “List.from_vector”List.from_vector <- function<T>(vector: T[]) -> list[T]#: <T> fn(vector: T[]) -> list[T]List.from_vector <- function(vector)The elements of an atomic vector as a list.
List.from_vector(c(3L, 1L, 2L))#> list(3L, 1L, 2L)List.to_vector
Section titled “List.to_vector”List.to_vector <- function<T>(list: list[T]) -> T[]#: <T> fn(list: list[T]) -> T[]List.to_vector <- function(list)The elements of a list as an atomic vector; every element must be a scalar of one type.
List.to_vector(list(3L, 1L, 2L))#> c(3L, 1L, 2L)List.len
Section titled “List.len”List.len <- function<T>(list: Array<T>) -> integerList.len <- function<T>(list: list[T]) -> integer#: <T> fn(list: Array<T>) -> integerList.len <- function(list)
#: <T> fn(list: list[T]) -> integerList.len <- function(list)The number of elements.
List.len(list("a", "b"))#> 2LList.is_empty
Section titled “List.is_empty”List.is_empty <- function<T>(list: Array<T>) -> logicalList.is_empty <- function<T>(list: list[T]) -> logical#: <T> fn(list: Array<T>) -> logicalList.is_empty <- function(list)
#: <T> fn(list: list[T]) -> logicalList.is_empty <- function(list)Whether the list has no elements.
List.is_empty(list())#> TRUEList.get
Section titled “List.get”List.get <- function<T>(list: Array<T>, index: integer) -> Result<T, :OutOfBounds>List.get <- function<T>(list: list[T], index: integer) -> Result<T, :OutOfBounds>#: <T> fn(list: Array<T>, index: integer) -> Result<T, :OutOfBounds>List.get <- function(list, index)
#: <T> fn(list: list[T], index: integer) -> Result<T, :OutOfBounds>List.get <- function(list, index)The element at a 1-based position, or :Err(:OutOfBounds).
List.get(list("a", "b"), 3L)#> :Err(:OutOfBounds)List.set
Section titled “List.set”List.set <- function<T>(list: Array<T>, index: integer, value: T) -> Array<T>List.set <- function<T>(list: list[T], index: integer, value: T) -> list[T]#: <T> fn(list: Array<T>, index: integer, value: T) -> Array<T>List.set <- function(list, index, value)
#: <T> fn(list: list[T], index: integer, value: T) -> list[T]List.set <- function(list, index, value)Replaces the element at a position; a position out of range leaves the list unchanged.
List.set(list("a", "b"), 2L, "z")#> list("a", "z")List.update
Section titled “List.update”List.update <- function<T>(list: Array<T>, index: integer, f: fn(T) -> T) -> Array<T>List.update <- function<T>(list: list[T], index: integer, f: fn(T) -> T) -> list[T]#: <T> fn(list: Array<T>, index: integer, f: fn(T) -> T) -> Array<T>List.update <- function(list, index, f)
#: <T> fn(list: list[T], index: integer, f: fn(T) -> T) -> list[T]List.update <- function(list, index, f)Replaces the element at a position with f of it.
List.update(list(1L, 2L), 1L, function(x) x + 10L)#> list(11L, 2L)List.append
Section titled “List.append”List.append <- function<T>(list: Array<T>, value: T) -> Array<T>List.append <- function<T>(list: list[T], value: T) -> list[T]#: <T> fn(list: Array<T>, value: T) -> Array<T>List.append <- function(list, value)
#: <T> fn(list: list[T], value: T) -> list[T]List.append <- function(list, value)Adds an element at the end.
List.append(list(1L, 2L), 3L)#> list(1L, 2L, 3L)List.prepend
Section titled “List.prepend”List.prepend <- function<T>(list: Array<T>, value: T) -> Array<T>List.prepend <- function<T>(list: list[T], value: T) -> list[T]#: <T> fn(list: Array<T>, value: T) -> Array<T>List.prepend <- function(list, value)
#: <T> fn(list: list[T], value: T) -> list[T]List.prepend <- function(list, value)Adds an element at the start.
List.prepend(list(1L, 2L), 0L)#> list(0L, 1L, 2L)List.concat
Section titled “List.concat”List.concat <- function<T>(first: Array<T>, second: Array<T>) -> Array<T>List.concat <- function<T>(first: list[T], second: list[T]) -> list[T]#: <T> fn(first: Array<T>, second: Array<T>) -> Array<T>List.concat <- function(first, second)
#: <T> fn(first: list[T], second: list[T]) -> list[T]List.concat <- function(first, second)The elements of first followed by those of second.
List.concat(list(1L), list(2L, 3L))#> list(1L, 2L, 3L)List.single
Section titled “List.single”List.single <- function<T>(value: T) -> list[T]#: <T> fn(value: T) -> list[T]List.single <- function(value)A list of one element.
List.single("only")#> list("only")List.repeat
Section titled “List.repeat”List.repeat <- function<T>(value: T, count: integer) -> list[T]#: <T> fn(value: T, count: integer) -> list[T]List.repeat <- function(value, count)A list of count copies of value.
List.repeat("x", 3L)#> list("x", "x", "x")List.range
Section titled “List.range”List.range <- function(start: integer, end: integer) -> list[integer]#: fn(start: integer, end: integer) -> list[integer]List.range <- function(start, end)The integers from start up to and including end, or an empty list when end is smaller.
Unlike R’s :, it never counts down.
Both List.range and List.repeat stop with an error when the list would hold more than
2,147,483,647 elements, the longest vector an R integer index reaches.
List.range(2L, 5L)#> list(2L, 3L, 4L, 5L)List.range(3L, 1L)#> list()List.reverse
Section titled “List.reverse”List.reverse <- function<T>(list: Array<T>) -> Array<T>List.reverse <- function<T>(list: list[T]) -> list[T]#: <T> fn(list: Array<T>) -> Array<T>List.reverse <- function(list)
#: <T> fn(list: list[T]) -> list[T]List.reverse <- function(list)The elements in reverse order.
List.reverse(list(1L, 2L, 3L))#> list(3L, 2L, 1L)List.join
Section titled “List.join”List.join <- function<T>(lists: Array<Array<T>>) -> Array<T>List.join <- function<T>(lists: list[list[T]]) -> list[T]#: <T> fn(lists: Array<Array<T>>) -> Array<T>List.join <- function(lists)
#: <T> fn(lists: list[list[T]]) -> list[T]List.join <- function(lists)Concatenates a list of lists.
List.join(list(list(1L), list(), list(2L, 3L)))#> list(1L, 2L, 3L)List.map
Section titled “List.map”List.map <- function<A, B: item>(list: Array<A>, f: fn(A) -> B) -> Array<B>List.map <- function<A, B>(list: list[A], f: fn(A) -> B) -> list[B]#: <A, B: item> fn(list: Array<A>, f: fn(A) -> B) -> Array<B>List.map <- function(list, f)
#: <A, B> fn(list: list[A], f: fn(A) -> B) -> list[B]List.map <- function(list, f)Applies f to every element.
List.map(list(1L, 2L, 3L), function(x) x * 2L)#> list(2L, 4L, 6L)List.map_with_index
Section titled “List.map_with_index”List.map_with_index <- function<A, B: item>(list: Array<A>, f: fn(A, integer) -> B) -> Array<B>List.map_with_index <- function<A, B>(list: list[A], f: fn(A, integer) -> B) -> list[B]#: <A, B: item> fn(list: Array<A>, f: fn(A, integer) -> B) -> Array<B>List.map_with_index <- function(list, f)
#: <A, B> fn(list: list[A], f: fn(A, integer) -> B) -> list[B]List.map_with_index <- function(list, f)Applies f to every element and its 1-based position.
List.map_with_index(list("a", "b"), function(x, i) Str.concat(x, Num.to_str(i)))#> list("a1", "b2")List.map2
Section titled “List.map2”List.map2 <- function<A, B, C: item>(first: Array<A>, second: Array<B>, f: fn(A, B) -> C) -> Array<C>List.map2 <- function<A, B, C>(first: list[A], second: list[B], f: fn(A, B) -> C) -> list[C]#: <A, B, C: item> fn(first: Array<A>, second: Array<B>, f: fn(A, B) -> C) -> Array<C>List.map2 <- function(first, second, f)
#: <A, B, C> fn(first: list[A], second: list[B], f: fn(A, B) -> C) -> list[C]List.map2 <- function(first, second, f)Applies f to the elements of two lists pairwise, stopping at the shorter one.
List.map2(list(1L, 2L, 3L), list(10L, 20L), function(a, b) a + b)#> list(11L, 22L)List.map3
Section titled “List.map3”List.map3 <- function<A, B, C, D: item>(first: Array<A>, second: Array<B>, third: Array<C>, f: fn(A, B, C) -> D) -> Array<D>List.map3 <- function<A, B, C, D>(first: list[A], second: list[B], third: list[C], f: fn(A, B, C) -> D) -> list[D]#: <A, B, C, D: item> fn(first: Array<A>, second: Array<B>, third: Array<C>, f: fn(A, B, C) -> D) -> Array<D>List.map3 <- function(first, second, third, f)
#: <A, B, C, D> fn(first: list[A], second: list[B], third: list[C], f: fn(A, B, C) -> D) -> list[D]List.map3 <- function(first, second, third, f)Applies f to the elements at each position of three lists, up to the shortest one.
List.map3(list(1L, 2L), list(10L, 20L), list(100L, 200L), function(a, b, c) a + b + c)#> list(111L, 222L)List.map4
Section titled “List.map4”List.map4 <- function<A, B, C, D, E: item>(first: Array<A>, second: Array<B>, third: Array<C>, fourth: Array<D>, f: fn(A, B, C, D) -> E) -> Array<E>List.map4 <- function<A, B, C, D, E>(first: list[A], second: list[B], third: list[C], fourth: list[D], f: fn(A, B, C, D) -> E) -> list[E]#: <A, B, C, D, E: item> fn(first: Array<A>, second: Array<B>, third: Array<C>, fourth: Array<D>, f: fn(A, B, C, D) -> E) -> Array<E>List.map4 <- function(first, second, third, fourth, f)
#: <A, B, C, D, E> fn(first: list[A], second: list[B], third: list[C], fourth: list[D], f: fn(A, B, C, D) -> E) -> list[E]List.map4 <- function(first, second, third, fourth, f)Applies f to the elements at each position of four lists, up to the shortest one.
List.map4(list(1L), list(2L), list(3L), list(4L), function(a, b, c, d) a * b * c * d)#> list(24L)List.join_map
Section titled “List.join_map”List.join_map <- function<A, B>(list: Array<A>, f: fn(A) -> Array<B>) -> Array<B>List.join_map <- function<A, B>(list: list[A], f: fn(A) -> list[B]) -> list[B]#: <A, B> fn(list: Array<A>, f: fn(A) -> Array<B>) -> Array<B>List.join_map <- function(list, f)
#: <A, B> fn(list: list[A], f: fn(A) -> list[B]) -> list[B]List.join_map <- function(list, f)Applies f, which returns a list, to every element and concatenates the results.
List.join_map(list(1L, 2L), function(x) list(x, x))#> list(1L, 1L, 2L, 2L)List.keep_if
Section titled “List.keep_if”List.keep_if <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>List.keep_if <- function<T>(list: list[T], predicate: fn(T) -> logical) -> list[T]#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>List.keep_if <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> list[T]List.keep_if <- function(list, predicate)The elements for which predicate is TRUE.
List.keep_if(list(1L, 5L, 2L), function(x) x > 1L)#> list(5L, 2L)List.keep_if_try
Section titled “List.keep_if_try”List.keep_if_try <- function<T, E>(list: Array<T>, predicate: fn(T) -> Result<logical, E>) -> Result<Array<T>, E>List.keep_if_try <- function<T, E>(list: list[T], predicate: fn(T) -> Result<logical, E>) -> Result<list[T], E>#: <T, E> fn(list: Array<T>, predicate: fn(T) -> Result<logical, E>) -> Result<Array<T>, E>List.keep_if_try <- function(list, predicate)
#: <T, E> fn(list: list[T], predicate: fn(T) -> Result<logical, E>) -> Result<list[T], E>List.keep_if_try <- function(list, predicate)The elements for which predicate returns :Ok(TRUE), or the first :Err it returns.
List.keep_if_try(list("1", "20", "3"), function(s) Result.map(Str.to_integer(s), function(n) n > 2L))#> :Ok(list("20", "3"))List.keep_if_try(list("1", "x"), function(s) Result.map(Str.to_integer(s), function(n) n > 2L))#> :Err(:InvalidNumStr)List.drop_if
Section titled “List.drop_if”List.drop_if <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>List.drop_if <- function<T>(list: list[T], predicate: fn(T) -> logical) -> list[T]#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Array<T>List.drop_if <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> list[T]List.drop_if <- function(list, predicate)The elements for which predicate is FALSE.
List.drop_if(list(1L, 5L, 2L), function(x) x > 1L)#> list(1L)List.keep_oks
Section titled “List.keep_oks”List.keep_oks <- function<A, B: item, E>(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<B>List.keep_oks <- function<A, B, E>(list: list[A], f: fn(A) -> Result<B, E>) -> list[B]#: <A, B: item, E> fn(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<B>List.keep_oks <- function(list, f)
#: <A, B, E> fn(list: list[A], f: fn(A) -> Result<B, E>) -> list[B]List.keep_oks <- function(list, f)Applies f to every element and keeps the :Ok values.
List.keep_oks(list("1", "x", "3"), Str.to_integer)#> list(1L, 3L)List.keep_errs
Section titled “List.keep_errs”List.keep_errs <- function<A, B, E: item>(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<E>List.keep_errs <- function<A, B, E>(list: list[A], f: fn(A) -> Result<B, E>) -> list[E]#: <A, B, E: item> fn(list: Array<A>, f: fn(A) -> Result<B, E>) -> Array<E>List.keep_errs <- function(list, f)
#: <A, B, E> fn(list: list[A], f: fn(A) -> Result<B, E>) -> list[E]List.keep_errs <- function(list, f)Applies f to every element and keeps the :Err values.
List.keep_errs(list("1", "x"), Str.to_integer)#> list(:InvalidNumStr)List.map_try
Section titled “List.map_try”List.map_try <- function<A, B: item, E>(list: Array<A>, f: fn(A) -> Result<B, E>) -> Result<Array<B>, E>List.map_try <- function<A, B, E>(list: list[A], f: fn(A) -> Result<B, E>) -> Result<list[B], E>#: <A, B: item, E> fn(list: Array<A>, f: fn(A) -> Result<B, E>) -> Result<Array<B>, E>List.map_try <- function(list, f)
#: <A, B, E> fn(list: list[A], f: fn(A) -> Result<B, E>) -> Result<list[B], E>List.map_try <- function(list, f)Applies f to every element and stops at the first :Err.
List.map_try(list("1", "2"), Str.to_integer)#> :Ok(list(1L, 2L))List.walk
Section titled “List.walk”List.walk <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> S) -> SList.walk <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> S) -> S#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> S) -> SList.walk <- function(list, state, f)
#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> S) -> SList.walk <- function(list, state, f)Folds from the first element: f gets the state and an element and returns the next state.
List.walk(list(1L, 2L, 3L), 0L, function(total, x) total + x)#> 6LList.walk_backwards
Section titled “List.walk_backwards”List.walk_backwards <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> S) -> SList.walk_backwards <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> S) -> S#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> S) -> SList.walk_backwards <- function(list, state, f)
#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> S) -> SList.walk_backwards <- function(list, state, f)Folds from the last element.
List.walk_backwards(list("a", "b", "c"), "", function(text, x) Str.concat(text, x))#> "cba"List.walk_until
Section titled “List.walk_until”List.walk_until <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_until <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_until <- function(list, state, f)
#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_until <- function(list, state, f)Folds until f returns :Break(state); :Continue(state) goes on.
List.walk_until(list(1L, 2L, 3L, 4L), 0L, function(total, x) if (total >= 3L) :Break(total) else :Continue(total + x))#> 3LList.walk_backwards_until
Section titled “List.walk_backwards_until”List.walk_backwards_until <- function<T, S>(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_backwards_until <- function<T, S>(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_backwards_until <- function(list, state, f)
#: <T, S> fn(list: list[T], state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_backwards_until <- function(list, state, f)Folds the list from the last element until f returns :Break(state).
List.walk_backwards_until(list(1L, 5L, 2L, 3L), 0L, function(total, x) if (x > 4L) :Break(total) else :Continue(total + x))#> 5LList.walk_with_index
Section titled “List.walk_with_index”List.walk_with_index <- function<T, S>(list: Array<T>, state: S, f: fn(S, T, integer) -> S) -> SList.walk_with_index <- function<T, S>(list: list[T], state: S, f: fn(S, T, integer) -> S) -> S#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T, integer) -> S) -> SList.walk_with_index <- function(list, state, f)
#: <T, S> fn(list: list[T], state: S, f: fn(S, T, integer) -> S) -> SList.walk_with_index <- function(list, state, f)Folds the list, passing f each element’s 1-based position too.
List.walk_with_index(list(10L, 20L, 30L), 0L, function(total, x, i) total + x * i)#> 140LList.walk_with_index_until
Section titled “List.walk_with_index_until”List.walk_with_index_until <- function<T, S>(list: Array<T>, state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> SList.walk_with_index_until <- function<T, S>(list: list[T], state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> S#: <T, S> fn(list: Array<T>, state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> SList.walk_with_index_until <- function(list, state, f)
#: <T, S> fn(list: list[T], state: S, f: fn(S, T, integer) -> :Continue(S) | :Break(S)) -> SList.walk_with_index_until <- function(list, state, f)Folds the list with positions until f returns :Break(state).
List.walk_with_index_until(list("a", "b", "c"), "", function(seen, x, i) if (i > 2L) :Break(seen) else :Continue(Str.concat(seen, x)))#> "ab"List.walk_from
Section titled “List.walk_from”List.walk_from <- function<T, S>(list: Array<T>, index: integer, state: S, f: fn(S, T) -> S) -> SList.walk_from <- function<T, S>(list: list[T], index: integer, state: S, f: fn(S, T) -> S) -> S#: <T, S> fn(list: Array<T>, index: integer, state: S, f: fn(S, T) -> S) -> SList.walk_from <- function(list, index, state, f)
#: <T, S> fn(list: list[T], index: integer, state: S, f: fn(S, T) -> S) -> SList.walk_from <- function(list, index, state, f)Folds the list from a 1-based position onwards.
List.walk_from(list(1L, 2L, 3L, 4L), 3L, 0L, function(total, x) total + x)#> 7LList.walk_from_until
Section titled “List.walk_from_until”List.walk_from_until <- function<T, S>(list: Array<T>, index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_from_until <- function<T, S>(list: list[T], index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> S#: <T, S> fn(list: Array<T>, index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_from_until <- function(list, index, state, f)
#: <T, S> fn(list: list[T], index: integer, state: S, f: fn(S, T) -> :Continue(S) | :Break(S)) -> SList.walk_from_until <- function(list, index, state, f)Folds the list from a position until f returns :Break(state).
List.walk_from_until(list(1L, 2L, 3L, 4L), 2L, 0L, function(total, x) if (total >= 5L) :Break(total) else :Continue(total + x))#> 5LList.walk_try
Section titled “List.walk_try”List.walk_try <- function<T, S, E>(list: Array<T>, state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>List.walk_try <- function<T, S, E>(list: list[T], state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>#: <T, S, E> fn(list: Array<T>, state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>List.walk_try <- function(list, state, f)
#: <T, S, E> fn(list: list[T], state: S, f: fn(S, T) -> Result<S, E>) -> Result<S, E>List.walk_try <- function(list, state, f)Folds the list while f returns :Ok(state), stopping at the first :Err.
List.walk_try(list("1", "2", "x"), 0L, function(total, s) Result.map(Str.to_integer(s), function(n) total + n))#> :Err(:InvalidNumStr)List.for_each
Section titled “List.for_each”List.for_each <- function<T>(list: Array<T>, f: fn(T) -> Any) -> NULLList.for_each <- function<T>(list: list[T], f: fn(T) -> Any) -> NULL#: <T> fn(list: Array<T>, f: fn(T) -> Any) -> NULLList.for_each <- function(list, f)
#: <T> fn(list: list[T], f: fn(T) -> Any) -> NULLList.for_each <- function(list, f)Calls f on each element for its effect, and returns NULL invisibly.
List.for_each(list("a", "b"), function(x) cat(x, "\n"))#> a#> bList.for_each_try
Section titled “List.for_each_try”List.for_each_try <- function<T, E>(list: Array<T>, f: fn(T) -> Result<Any, E>) -> Result<NULL, E>List.for_each_try <- function<T, E>(list: list[T], f: fn(T) -> Result<Any, E>) -> Result<NULL, E>#: <T, E> fn(list: Array<T>, f: fn(T) -> Result<Any, E>) -> Result<NULL, E>List.for_each_try <- function(list, f)
#: <T, E> fn(list: list[T], f: fn(T) -> Result<Any, E>) -> Result<NULL, E>List.for_each_try <- function(list, f)Calls f on each element, stopping at the first :Err.
List.for_each_try(list(1L, -2L, 3L), function(x) if (x < 0L) :Err(:Negative(x)) else :Ok(NULL))#> :Err(:Negative(-2L))List.any
Section titled “List.any”List.any <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> logicalList.any <- function<T>(list: list[T], predicate: fn(T) -> logical) -> logical#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> logicalList.any <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> logicalList.any <- function(list, predicate)Whether predicate is TRUE for some element.
List.any(list(1L, 5L), function(x) x > 4L)#> TRUEList.all
Section titled “List.all”List.all <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> logicalList.all <- function<T>(list: list[T], predicate: fn(T) -> logical) -> logical#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> logicalList.all <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> logicalList.all <- function(list, predicate)Whether predicate is TRUE for every element; TRUE for an empty list.
List.all(list(1L, 5L), function(x) x > 4L)#> FALSEList.contains
Section titled “List.contains”List.contains <- function<T>(list: Array<T>, value: T) -> logicalList.contains <- function<T>(list: list[T], value: T) -> logical#: <T> fn(list: Array<T>, value: T) -> logicalList.contains <- function(list, value)
#: <T> fn(list: list[T], value: T) -> logicalList.contains <- function(list, value)Whether some element is identical() to value.
List.contains(list("a", "b"), "b")#> TRUEList.count_if
Section titled “List.count_if”List.count_if <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> integerList.count_if <- function<T>(list: list[T], predicate: fn(T) -> logical) -> integer#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> integerList.count_if <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> integerList.count_if <- function(list, predicate)The number of elements for which predicate is TRUE.
List.count_if(list(1L, 5L, 7L), function(x) x > 4L)#> 2LList.find_first
Section titled “List.find_first”List.find_first <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>List.find_first <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>List.find_first <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>List.find_first <- function(list, predicate)The first element for which predicate is TRUE, or :Err(:NotFound).
List.find_first(list(1L, 5L, 7L), function(x) x > 4L)#> :Ok(5L)List.find_last
Section titled “List.find_last”List.find_last <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>List.find_last <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<T, :NotFound>List.find_last <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<T, :NotFound>List.find_last <- function(list, predicate)The last element for which predicate is TRUE, or :Err(:NotFound).
List.find_last(list(1L, 5L, 7L), function(x) x > 4L)#> :Ok(7L)List.find_first_index
Section titled “List.find_first_index”List.find_first_index <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>List.find_first_index <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>List.find_first_index <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>List.find_first_index <- function(list, predicate)The position of the first match, or :Err(:NotFound).
List.find_first_index(list(1L, 5L, 7L), function(x) x > 4L)#> :Ok(2L)List.find_last_index
Section titled “List.find_last_index”List.find_last_index <- function<T>(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>List.find_last_index <- function<T>(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>#: <T> fn(list: Array<T>, predicate: fn(T) -> logical) -> Result<integer, :NotFound>List.find_last_index <- function(list, predicate)
#: <T> fn(list: list[T], predicate: fn(T) -> logical) -> Result<integer, :NotFound>List.find_last_index <- function(list, predicate)The position of the last match, or :Err(:NotFound).
List.find_last_index(list(1L, 5L, 7L), function(x) x > 9L)#> :Err(:NotFound)List.first
Section titled “List.first”List.first <- function<T>(list: Array<T>) -> Result<T, :ListWasEmpty>List.first <- function<T>(list: list[T]) -> Result<T, :ListWasEmpty>#: <T> fn(list: Array<T>) -> Result<T, :ListWasEmpty>List.first <- function(list)
#: <T> fn(list: list[T]) -> Result<T, :ListWasEmpty>List.first <- function(list)The first element, or :Err(:ListWasEmpty).
List.first(list("a", "b"))#> :Ok("a")List.last
Section titled “List.last”List.last <- function<T>(list: Array<T>) -> Result<T, :ListWasEmpty>List.last <- function<T>(list: list[T]) -> Result<T, :ListWasEmpty>#: <T> fn(list: Array<T>) -> Result<T, :ListWasEmpty>List.last <- function(list)
#: <T> fn(list: list[T]) -> Result<T, :ListWasEmpty>List.last <- function(list)The last element, or :Err(:ListWasEmpty).
List.last(list())#> :Err(:ListWasEmpty)List.take_first
Section titled “List.take_first”List.take_first <- function<T>(list: Array<T>, count: integer) -> Array<T>List.take_first <- function<T>(list: list[T], count: integer) -> list[T]#: <T> fn(list: Array<T>, count: integer) -> Array<T>List.take_first <- function(list, count)
#: <T> fn(list: list[T], count: integer) -> list[T]List.take_first <- function(list, count)The first count elements, or all of them if there are fewer.
List.take_first(list(1L, 2L, 3L), 2L)#> list(1L, 2L)List.take_last
Section titled “List.take_last”List.take_last <- function<T>(list: Array<T>, count: integer) -> Array<T>List.take_last <- function<T>(list: list[T], count: integer) -> list[T]#: <T> fn(list: Array<T>, count: integer) -> Array<T>List.take_last <- function(list, count)
#: <T> fn(list: list[T], count: integer) -> list[T]List.take_last <- function(list, count)The last count elements.
List.take_last(list(1L, 2L, 3L), 2L)#> list(2L, 3L)List.drop_first
Section titled “List.drop_first”List.drop_first <- function<T>(list: Array<T>, count: integer) -> Array<T>List.drop_first <- function<T>(list: list[T], count: integer) -> list[T]#: <T> fn(list: Array<T>, count: integer) -> Array<T>List.drop_first <- function(list, count)
#: <T> fn(list: list[T], count: integer) -> list[T]List.drop_first <- function(list, count)Everything but the first count elements.
List.drop_first(list(1L, 2L, 3L), 2L)#> list(3L)List.drop_last
Section titled “List.drop_last”List.drop_last <- function<T>(list: Array<T>, count: integer) -> Array<T>List.drop_last <- function<T>(list: list[T], count: integer) -> list[T]#: <T> fn(list: Array<T>, count: integer) -> Array<T>List.drop_last <- function(list, count)
#: <T> fn(list: list[T], count: integer) -> list[T]List.drop_last <- function(list, count)Everything but the last count elements.
List.drop_last(list(1L, 2L, 3L), 2L)#> list(1L)List.drop_at
Section titled “List.drop_at”List.drop_at <- function<T>(list: Array<T>, index: integer) -> Array<T>List.drop_at <- function<T>(list: list[T], index: integer) -> list[T]#: <T> fn(list: Array<T>, index: integer) -> Array<T>List.drop_at <- function(list, index)
#: <T> fn(list: list[T], index: integer) -> list[T]List.drop_at <- function(list, index)Removes the element at a position.
List.drop_at(list("a", "b", "c"), 2L)#> list("a", "c")List.sublist
Section titled “List.sublist”List.sublist <- function<T>(list: Array<T>, start: integer, count: integer) -> Array<T>List.sublist <- function<T>(list: list[T], start: integer, count: integer) -> list[T]#: <T> fn(list: Array<T>, start: integer, count: integer) -> Array<T>List.sublist <- function(list, start, count)
#: <T> fn(list: list[T], start: integer, count: integer) -> list[T]List.sublist <- function(list, start, count)count elements starting at position start.
List.sublist(list(1L, 2L, 3L, 4L), 2L, 2L)#> list(2L, 3L)List.split_at
Section titled “List.split_at”List.split_at <- function<T>(list: Array<T>, count: integer) -> Record{before: Array<T>, others: Array<T>}List.split_at <- function<T>(list: list[T], count: integer) -> Record{before: list[T], others: list[T]}#: <T> fn(list: Array<T>, count: integer) -> Record{before: Array<T>, others: Array<T>}List.split_at <- function(list, count)
#: <T> fn(list: list[T], count: integer) -> Record{before: list[T], others: list[T]}List.split_at <- function(list, count)The first count elements as before and the rest as others.
List.split_at(list(1L, 2L, 3L), 1L)#> (before = list(1L), others = list(2L, 3L))List.split_first
Section titled “List.split_first”List.split_first <- function<T>(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>List.split_first <- function<T>(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>#: <T> fn(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>List.split_first <- function(list, delimiter)
#: <T> fn(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>List.split_first <- function(list, delimiter)Splits the list around the first element identical to delimiter.
List.split_first(list("a", "-", "b", "-", "c"), "-")#> :Ok((after = list("b", "-", "c"), before = list("a")))List.split_last
Section titled “List.split_last”List.split_last <- function<T>(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>List.split_last <- function<T>(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>#: <T> fn(list: Array<T>, delimiter: T) -> Result<Record{before: Array<T>, after: Array<T>}, :NotFound>List.split_last <- function(list, delimiter)
#: <T> fn(list: list[T], delimiter: T) -> Result<Record{before: list[T], after: list[T]}, :NotFound>List.split_last <- function(list, delimiter)Splits the list around the last element identical to delimiter.
List.split_last(list("a", "-", "b", "-", "c"), "-")#> :Ok((after = list("c"), before = list("a", "-", "b")))List.split_on
Section titled “List.split_on”List.split_on <- function<T>(list: Array<T>, delimiter: T) -> Array<Array<T>>List.split_on <- function<T>(list: list[T], delimiter: T) -> list[list[T]]#: <T> fn(list: Array<T>, delimiter: T) -> Array<Array<T>>List.split_on <- function(list, delimiter)
#: <T> fn(list: list[T], delimiter: T) -> list[list[T]]List.split_on <- function(list, delimiter)The runs of elements between elements identical to delimiter.
List.split_on(list(1L, 0L, 2L, 3L, 0L, 4L), 0L)#> list(list(1L), list(2L, 3L), list(4L))List.split_on_list
Section titled “List.split_on_list”List.split_on_list <- function<T>(list: Array<T>, delimiter: Array<T>) -> Array<Array<T>>List.split_on_list <- function<T>(list: list[T], delimiter: list[T]) -> list[list[T]]#: <T> fn(list: Array<T>, delimiter: Array<T>) -> Array<Array<T>>List.split_on_list <- function(list, delimiter)
#: <T> fn(list: list[T], delimiter: list[T]) -> list[list[T]]List.split_on_list <- function(list, delimiter)The runs of elements between occurrences of the sublist delimiter.
List.split_on_list(list(1L, 0L, 0L, 2L, 0L, 3L), list(0L, 0L))#> list(list(1L), list(2L, 0L, 3L))List.chunks_of
Section titled “List.chunks_of”List.chunks_of <- function<T>(list: Array<T>, size: integer) -> Array<Array<T>>List.chunks_of <- function<T>(list: list[T], size: integer) -> list[list[T]]#: <T> fn(list: Array<T>, size: integer) -> Array<Array<T>>List.chunks_of <- function(list, size)
#: <T> fn(list: list[T], size: integer) -> list[list[T]]List.chunks_of <- function(list, size)Groups of size elements; the last group may be shorter.
List.chunks_of(list(1L, 2L, 3L), 2L)#> list(list(1L, 2L), list(3L))List.intersperse
Section titled “List.intersperse”List.intersperse <- function<T>(list: Array<T>, separator: T) -> Array<T>List.intersperse <- function<T>(list: list[T], separator: T) -> list[T]#: <T> fn(list: Array<T>, separator: T) -> Array<T>List.intersperse <- function(list, separator)
#: <T> fn(list: list[T], separator: T) -> list[T]List.intersperse <- function(list, separator)Puts separator between every two elements.
List.intersperse(list("a", "b", "c"), "-")#> list("a", "-", "b", "-", "c")List.sort_with
Section titled “List.sort_with”List.sort_with <- function<T>(list: Array<T>, compare: fn(T, T) -> :LT | :EQ | :GT) -> Array<T>List.sort_with <- function<T>(list: list[T], compare: fn(T, T) -> :LT | :EQ | :GT) -> list[T]#: <T> fn(list: Array<T>, compare: fn(T, T) -> :LT | :EQ | :GT) -> Array<T>List.sort_with <- function(list, compare)
#: <T> fn(list: list[T], compare: fn(T, T) -> :LT | :EQ | :GT) -> list[T]List.sort_with <- function(list, compare)A stable sort by compare, which returns :LT, :EQ or :GT.
List.sort_with(list(3L, 1L, 2L), Num.compare)#> list(1L, 2L, 3L)List.sort_asc
Section titled “List.sort_asc”List.sort_asc <- function<T: scalar numeric>(list: Array<T>) -> Array<T>List.sort_asc <- function<T: scalar numeric>(list: list[T]) -> list[T]#: <T: scalar numeric> fn(list: Array<T>) -> Array<T>List.sort_asc <- function(list)
#: <T: scalar numeric> fn(list: list[T]) -> list[T]List.sort_asc <- function(list)Sorts numbers from smallest to largest.
List.sort_asc(list(3L, 1L, 2L))#> list(1L, 2L, 3L)List.sort_desc
Section titled “List.sort_desc”List.sort_desc <- function<T: scalar numeric>(list: Array<T>) -> Array<T>List.sort_desc <- function<T: scalar numeric>(list: list[T]) -> list[T]#: <T: scalar numeric> fn(list: Array<T>) -> Array<T>List.sort_desc <- function(list)
#: <T: scalar numeric> fn(list: list[T]) -> list[T]List.sort_desc <- function(list)Sorts numbers from largest to smallest.
List.sort_desc(list(1.5, 3, 2))#> list(3, 2, 1.5)List.swap
Section titled “List.swap”List.swap <- function<T>(list: Array<T>, first: integer, second: integer) -> Array<T>List.swap <- function<T>(list: list[T], first: integer, second: integer) -> list[T]#: <T> fn(list: Array<T>, first: integer, second: integer) -> Array<T>List.swap <- function(list, first, second)
#: <T> fn(list: list[T], first: integer, second: integer) -> list[T]List.swap <- function(list, first, second)Exchanges the elements at two positions; an out-of-range position leaves the list unchanged.
List.swap(list("a", "b", "c"), 1L, 3L)#> list("c", "b", "a")List.replace
Section titled “List.replace”List.replace <- function<T>(list: Array<T>, index: integer, value: T) -> Record{list: Array<T>, value: T}List.replace <- function<T>(list: list[T], index: integer, value: T) -> Record{list: list[T], value: T}#: <T> fn(list: Array<T>, index: integer, value: T) -> Record{list: Array<T>, value: T}List.replace <- function(list, index, value)
#: <T> fn(list: list[T], index: integer, value: T) -> Record{list: list[T], value: T}List.replace <- function(list, index, value)Replaces the element at a position, returning the new list and the element it replaced.
List.replace(list("a", "b"), 2L, "z")#> (list = list("a", "z"), value = "b")List.append_if_ok
Section titled “List.append_if_ok”List.append_if_ok <- function<T, E>(list: Array<T>, result: Result<T, E>) -> Array<T>List.append_if_ok <- function<T, E>(list: list[T], result: Result<T, E>) -> list[T]#: <T, E> fn(list: Array<T>, result: Result<T, E>) -> Array<T>List.append_if_ok <- function(list, result)
#: <T, E> fn(list: list[T], result: Result<T, E>) -> list[T]List.append_if_ok <- function(list, result)Adds an :Ok value at the end; an :Err leaves the list unchanged.
List.append_if_ok(list(1L), Str.to_integer("2"))#> list(1L, 2L)List.prepend_if_ok
Section titled “List.prepend_if_ok”List.prepend_if_ok <- function<T, E>(list: Array<T>, result: Result<T, E>) -> Array<T>List.prepend_if_ok <- function<T, E>(list: list[T], result: Result<T, E>) -> list[T]#: <T, E> fn(list: Array<T>, result: Result<T, E>) -> Array<T>List.prepend_if_ok <- function(list, result)
#: <T, E> fn(list: list[T], result: Result<T, E>) -> list[T]List.prepend_if_ok <- function(list, result)Adds an :Ok value at the start; an :Err leaves the list unchanged.
List.prepend_if_ok(list(1L), Str.to_integer("x"))#> list(1L)List.concat_utf8
Section titled “List.concat_utf8”List.concat_utf8 <- function(list: Array<integer>, string: character) -> Array<integer>List.concat_utf8 <- function(list: list[integer], string: character) -> list[integer]#: fn(list: Array<integer>, string: character) -> Array<integer>List.concat_utf8 <- function(list, string)
#: fn(list: list[integer], string: character) -> list[integer]List.concat_utf8 <- function(list, string)Appends the UTF-8 bytes of a string to a list of bytes.
List.concat_utf8(list(104L), "i")#> list(104L, 105L)List.with_capacity
Section titled “List.with_capacity”List.with_capacity <- function<T>(capacity: integer) -> list[T]#: <T> fn(capacity: integer) -> list[T]List.with_capacity <- function(capacity)An empty list with room for capacity elements, so appending that many never copies.
List.len(List.with_capacity(1000L))#> 0LList.reserve
Section titled “List.reserve”List.reserve <- function<T>(list: Array<T>, spare: integer) -> Array<T>List.reserve <- function<T>(list: list[T], spare: integer) -> list[T]#: <T> fn(list: Array<T>, spare: integer) -> Array<T>List.reserve <- function(list, spare)
#: <T> fn(list: list[T], spare: integer) -> list[T]List.reserve <- function(list, spare)The list with room for spare more elements.
List.reserve(list(1L, 2L), 100L)#> list(1L, 2L)List.release_excess_capacity
Section titled “List.release_excess_capacity”List.release_excess_capacity <- function<T>(list: Array<T>) -> Array<T>List.release_excess_capacity <- function<T>(list: list[T]) -> list[T]#: <T> fn(list: Array<T>) -> Array<T>List.release_excess_capacity <- function(list)
#: <T> fn(list: list[T]) -> list[T]List.release_excess_capacity <- function(list)The list with no room beyond its elements, which gives back what List.reserve or
List.with_capacity set aside.
List.release_excess_capacity(List.reserve(list(1L, 2L), 100L))#> list(1L, 2L)List.sum
Section titled “List.sum”List.sum <- function<T: scalar numeric>(list: Array<T>) -> TList.sum <- function<T: scalar numeric>(list: list[T]) -> T#: <T: scalar numeric> fn(list: Array<T>) -> TList.sum <- function(list)
#: <T: scalar numeric> fn(list: list[T]) -> TList.sum <- function(list)The sum of the elements; 0L for an empty list. An integer sum that overflows is an error, so
sum doubles, or fold with Num.add_checked to get :Err(:Overflow) instead. A double sum is
accumulated like R’s sum(), with more precision than a plain left-to-right fold, so
List.sum(xs) and sum(xs) give the same number.
List.sum(list(1L, 2L, 3L))#> 6LList.product
Section titled “List.product”List.product <- function<T: scalar numeric>(list: Array<T>) -> TList.product <- function<T: scalar numeric>(list: list[T]) -> T#: <T: scalar numeric> fn(list: Array<T>) -> TList.product <- function(list)
#: <T: scalar numeric> fn(list: list[T]) -> TList.product <- function(list)The product of the elements; 1L for an empty list. An integer product that overflows is an
error, as for List.sum.
List.product(list(2, 2.5))#> 5List.min
Section titled “List.min”List.min <- function<T: scalar numeric>(list: Array<T>) -> Result<T, :ListWasEmpty>List.min <- function<T: scalar numeric>(list: list[T]) -> Result<T, :ListWasEmpty>#: <T: scalar numeric> fn(list: Array<T>) -> Result<T, :ListWasEmpty>List.min <- function(list)
#: <T: scalar numeric> fn(list: list[T]) -> Result<T, :ListWasEmpty>List.min <- function(list)The smallest element, or :Err(:ListWasEmpty).
List.min(list(3L, 1L, 2L))#> :Ok(1L)List.max
Section titled “List.max”List.max <- function<T: scalar numeric>(list: Array<T>) -> Result<T, :ListWasEmpty>List.max <- function<T: scalar numeric>(list: list[T]) -> Result<T, :ListWasEmpty>#: <T: scalar numeric> fn(list: Array<T>) -> Result<T, :ListWasEmpty>List.max <- function(list)
#: <T: scalar numeric> fn(list: list[T]) -> Result<T, :ListWasEmpty>List.max <- function(list)The largest element, or :Err(:ListWasEmpty).
List.max(list())#> :Err(:ListWasEmpty)List.starts_with
Section titled “List.starts_with”List.starts_with <- function<T>(list: Array<T>, prefix: Array<T>) -> logicalList.starts_with <- function<T>(list: list[T], prefix: list[T]) -> logical#: <T> fn(list: Array<T>, prefix: Array<T>) -> logicalList.starts_with <- function(list, prefix)
#: <T> fn(list: list[T], prefix: list[T]) -> logicalList.starts_with <- function(list, prefix)Whether the list begins with the elements of prefix.
List.starts_with(list(1L, 2L, 3L), list(1L, 2L))#> TRUEList.ends_with
Section titled “List.ends_with”List.ends_with <- function<T>(list: Array<T>, suffix: Array<T>) -> logicalList.ends_with <- function<T>(list: list[T], suffix: list[T]) -> logical#: <T> fn(list: Array<T>, suffix: Array<T>) -> logicalList.ends_with <- function(list, suffix)
#: <T> fn(list: list[T], suffix: list[T]) -> logicalList.ends_with <- function(list, suffix)Whether the list ends with the elements of suffix.
List.ends_with(list(1L, 2L, 3L), list(2L))#> FALSE