SagaSaga
Standard Library

Std.Array

Types

Array

opaque type Array a

A persistent, immutable indexed collection backed by Erlang's array module. Provides O(log n) random access by index — much faster than linked lists for index-heavy workloads, but slower than lists for sequential processing.

Functions

new

fun new : Unit -> Array a

Creates a new empty array.

from_list

fun from_list : (xs: List a) -> Array a

Creates an array from a list.

size

fun size : (arr: Array a) -> Int

Returns the number of elements in the array.

get

fun get : (index: Int) -> (arr: Array a) -> Maybe a

Gets the element at the given index. Returns Nothing if out of bounds.

set

fun set : (index: Int) -> (value: a) -> (arr: Array a) -> Array a

Sets the element at the given index, returning a new array. If the index is beyond the current size, the array is extended with a default value.

to_list

fun to_list : (arr: Array a) -> List a

Converts an array to a list.

map

fun map : (f: a -> b) -> (arr: Array a) -> Array b

Applies a function to every element, returning a new array.

foldl

fun foldl : (f: b -> a -> b) -> (acc: b) -> (arr: Array a) -> b

Left fold over the array elements, in index order.