Std.Array
opaque type Array[A]An immutable sequence of values of type A, of fixed length, read by position.
fn empty[A]() -> Array[A]The array of no elements.
from_list
Section titled “from_list”fn from_list[A](xs: List[A]) -> Array[A]The elements in the order of xs.
to_list
Section titled “to_list”fn to_list[A](a: Array[A]) -> List[A]The elements in order.
repeat
Section titled “repeat”fn repeat[A](value: A, count: Int) -> Array[A]count copies of value. Empty if count is not positive.
fn size[A](a: Array[A]) -> IntThe number of elements.
is_empty
Section titled “is_empty”fn is_empty[A](a: Array[A]) -> BoolWhether there are no elements.
fn get[A](a: Array[A], index: Int) -> Option[A]The element at index. None if out of range or negative.
fn set[A](a: Array[A], index: Int, value: A) -> Array[A]The elements of a with the one at index replaced by value. A defect if index is out of
range or negative. On WASM and C, it updates a in place when a is referred to from nowhere
else.
fn slice[A](a: Array[A], from: Int, to: Int) -> Array[A]The elements from from inclusive to to exclusive. Both are clamped to 0 to size(a); empty
if from is not less than to.
append
Section titled “append”fn append[A](a: Array[A], b: Array[A]) -> Array[A]The elements of a, then those of b.
concat
Section titled “concat”fn concat[A](parts: List[Array[A]]) -> Array[A]The elements of all of them in order.
reverse
Section titled “reverse”fn reverse[A](a: Array[A]) -> Array[A]The elements in reverse order.
fn map[A, B](a: Array[A], f: fn(A) -> B fails E(f) uses { R(f) }) -> Array[B] fails E(f) uses { R(f) }Applies f to each element, from the first.
fn each[A](a: Array[A], f: fn(A) -> () fails E(f) uses { R(f) }) -> () fails E(f) uses { R(f) }Calls f on each element, from the first. Stops at the first failure.
fn fold[A, B](a: Array[A], from: B, f: fn(B, A) -> B fails E(f) uses { R(f) }) -> B fails E(f) uses { R(f) }Folds from the first element: f(f(f(from, a0), a1), a2).
find_index
Section titled “find_index”fn find_index[A](a: Array[A], f: fn(A) -> Bool fails E(f) uses { R(f) }) -> Option[Int] fails E(f) uses { R(f) }The position of the first element that gives True.
sort_by
Section titled “sort_by”fn sort_by[A](a: Array[A], f: fn(A, A) -> Ordering fails E(f) uses { R(f) }) -> Array[A] fails E(f) uses { R(f) }Sorts in the order of f. Stable, with the same result as List.sort_by.
fn sort[A: Ord](a: Array[A]) -> Array[A]Sorts in the Ord order. Stable.
lower_bound
Section titled “lower_bound”fn lower_bound[A: Ord](a: Array[A], value: A) -> IntIn an array sorted in the Ord order, the smallest position whose element is not less than
value: the position where value would be inserted to keep the order. size(a) if every
element is less. The bisection is fixed, so the result is the same on every target even when
a is not sorted.
binary_search
Section titled “binary_search”fn binary_search[A: Ord](a: Array[A], value: A) -> Option[Int]In an array sorted in the Ord order, the smallest position whose element is equal to value.
None if there is none.