Vector (dynamic array) operations backed by Erlang lists.

A Vector is represented as a tagged tuple %[:vector, length, list]. The length is tracked at the type level for dependent-type verification; at runtime it is a plain Int kept in sync with the underlying list.

Examples

use Std.Vector

let v = from_list([1, 2, 3])
length(v)                               # => 3
head(cons(0, v))                        # => 0
to_list(map(v, fn(x) -> x * x))         # => [1, 4, 9]

Functions

  • # fn __group__() -> Atom

    Group tag consumed by Cure.Stdlib.Preload.

  • # fn append(a: Tuple, b: Tuple) -> Tuple

    Concatenate two vectors.

  • # fn cons(x: T, vec: Tuple) -> Tuple

    Prepend x to the front of the vector.

  • # fn empty() -> Tuple

    Empty vector.

  • # fn from_list(list: List(T)) -> Tuple

    Build a vector from a list. Length is computed once up front.

  • # fn head(vec: Tuple) -> T

    First element of the vector; returns 0 when empty.

  • # fn is_empty(vec: Tuple) -> Bool

    true when the vector has no elements.

  • # fn length(vec: Tuple) -> Int

    Length of the vector.

  • # fn map(vec: Tuple, f: (T) -> U) -> Tuple

    Map f over every element of the vector; preserves length.

  • # fn singleton(x: T) -> Tuple

    Vector with a single element.

  • # fn tail(vec: Tuple) -> Tuple

    All-but-first elements of the vector; returns empty() when empty.

  • # fn to_list(vec: Tuple) -> List(T)

    Return the underlying list of elements.