array
Functions
build
fn(initial_state: 'a, step_fn: fn ('a) -> ('a, 'b, Bool) / 't109) -> (Array<'b>, 'a) / 't109
Builds an array by repeatedly calling step_fn(state) -> (new_state, value, done). Always produces at least 1 element. Returns (array, final_state).
concat
fn(left: Array<'t>, right: Array<'t>) -> Array<'t>
Concatenates two arrays, returning a new array that contains the items in left followed by the items in right.
filter
fn(arr: Array<'t>, predicate: fn ('t) -> Bool / 't708) -> Array<'t> / { 't708, 't708, 't708, ..'t708 }
Returns a new array containing only items for which predicate returns true. If all items pass, returns the original array (preserving referential equality).
filter_map
fn(array: Array<'a>, f: fn ('a) -> Option<'b> / 't781) -> Array<'b> / { 't781, 't781, 't781, ..'t781 }
Returns a new array containing only the elements for which f returns Some, unwrapping the values. Elements for which f returns None are skipped.
first
fn(array: Array<'t>) -> Option<'t>
Returns the first item in the array, or None if it is empty.
fold_right
fn(array: Array<'a>, init: 'b, reducer: fn ('b, 'a) -> 'b / 't627) -> 'b / { 't627, ..'t628 }
get
fn(array: Array<'t>, index: Int) -> Option<'t>
Returns the item at the given index, or None if the index is out of bounds.
import core/option { Some, None }
let a = [1, 2, 3];
test.assert_eq(array.get(a, 1), Some(2));
test.assert_eq(array.get(a, 5), None);head
fn(array: Array<'t>) -> Array<'t>
Returns a new array containing all but the last item in this array.
insert
fn(array: Array<'t>, index: Int, item: 't) -> Array<'t>
Returns a new array with the item inserted at the given index, shifting subsequent elements to the right.
length
fn(array: Array<'t>) -> Int
Returns the length of the array.
map
fn(array: Array<'a>, map_fn: fn ('a) -> 'b / 't644) -> Array<'b> / 't644
map_with_accumulator
fn(array: Array<'a>, acc: 'acc, f: fn ('acc, 'a) -> ('acc, 'b) / 't203) -> (Array<'b>, 'acc) / 't203
Maps over an array while threading an accumulator through each step. f(acc, item) -> (new_acc, mapped_item). Returns (mapped_array, final_acc).
new
∀ 't . fn () -> Array<'t>
Creates a new empty array.
new_from
fn(length: Int, offset: Int, map_fn: fn (Int) -> 't / 't360) -> Array<'t> / 't360
Creates a new array of length length, filling each index n with the result of mapFn(n).
pop
fn(array: Array<'t>) -> (Array<'t>, Option<'t>)
Removes the list item from an array, returning a new array and the removed item.
push
fn(array: Array<'t>, item: 't) -> Array<'t>
Returns a new array with the item appended to the end, without modifying the original array.
reduce
fn(array: Array<'a>, start: 'b, reducer: fn ('b, 'a) -> 'b / 't604) -> 'b / { 't604, ..'t605 }
remove
fn(array: Array<'t>, index: Int) -> (Array<'t>, Option<'t>)
Returns a new array with the item at the given index removed, without modifying the original array, and the value that was previously at that index.
remove_at
fn(arr: Array<'t>, index: Int) -> Array<'t>
Returns a new array with the item at the given index removed. Does not return the removed value. No bounds checking.
set
fn(array: Array<'t>, index: Int, value: 't) -> Array<'t>
Returns a new array, updating the item at the given index to the new value.
If the index is outside the bounds of the array, the original array is returned.
singleton
fn(item: 't) -> Array<'t>
Creates a new array containing a single item.
slice
fn(array: Array<'t>, start: Int, end: Int) -> Array<'t>
Returns a new array containing elements from index start (inclusive) to index end (exclusive). Returns the original array if bounds are invalid.
tail
fn(array: Array<'t>) -> Array<'t>
Returns a new array containing all but the first item in this array.
unchecked_get
fn(array: Array<'t>, index: Int) -> 't
Returns the item at the given index without bounds checking.
unchecked_pop
fn(array: Array<'t>) -> (Array<'t>, 't)
Removes the list item from an array, returning a new array and the removed item, without bounds checking.
unchecked_set
fn(array: Array<'t>, index: Int, value: 't) -> Array<'t>
Returns a new array, updating the item at the given index to the new value,
unfold_from
fn(collection: 'a, is_empty: Bool, next: fn ('a) -> ('a, 'b, Bool) / 't127) -> Array<'b> / 't127
Builds a new array by repeatedly unfolding a collection.
Takes an initial state and a next function. next(state) returns (newState, value, done):
valueis always included in the result arraydone = truemeans this was the last valuedone = falsemeans keep going withnewState
This is O(n) — an internal array is safely in place, not copied for each step.