tur/vec

stdlib/vec.tur
defn

vec-new

(vec-new)

allocate a new empty vec.

Since: Phase B1

defn

vec-len

(vec-len [v] :int)

return the number of elements in a vec.

vvec pointer returned by vec-new

Since: Phase B1

defn

vec-get

(vec-get [v i] :int)

return the element at index i (bounds-checked).

vvec pointer
izero-based index

Since: Phase B1

defn

vec-push!

(vec-push! [v val])

append a value to the end of a vec, growing storage as needed.

vvec pointer
valvalue to append

Since: Phase B1

defn

vec-pop!

(vec-pop! [v] :int)

remove and return the last element of a vec.

vvec pointer (must be non-empty)

Since: Phase B1

defn

vec-free

(vec-free [v])

free a vec and its backing data buffer.

vvec pointer to free

Since: Phase B1

definstance

Functor[vec]

(definstance Functor [vec])

fmap applies a function to every element, returning a new vec.

definstance

Foldable[vec]

(definstance Foldable [vec])

foldl and foldr fold a vec with an accumulator function.

definstance

Applicative[vec]

(definstance Applicative [vec])

pure wraps a value; ap applies each function to each value.

definstance

Monad[vec]

(definstance Monad [vec])

bind maps fn over each element and flattens the results.

definstance

Traversable[vec]

(definstance Traversable [vec])

traverse maps an effectful function over a vec, collecting results.

definstance

Alternative[vec]

(definstance Alternative [vec])

empty returns []; alt-or concatenates two vecs.

defn

vec-eq?

(vec-eq? [v1 v2 cmp-fn] :bool)

compare two vecs element-wise using a comparator function.

v1first vec pointer
v2second vec pointer
cmp-fncomparator fn [a :int b :int] :bool applied to each element pair

Since: Phase E1

definstance

Eq[vec]

(definstance Eq [vec])

eq? compares two vecs using integer equality on each element.

definstance

Clone[vec]

(definstance Clone [vec])

clone deep-copies the vec struct and all its elements.

Internal definitions
__functor_vec_fmap-- apply fn to every element and return a new vec.
__foldable_vec_foldl-- strict left fold over a vec.
__foldable_vec_foldr-- right fold over a vec.
__applicative_vec_pure-- wrap a single value in a one-element vec.
__applicative_vec_ap-- apply a vec of functions to a vec of values (cartesian product).
__monad_vec_concat-- flatten a vec of vecs into a single vec.
__monad_vec_bind-- map fn over each element and flatten the resulting vec of vecs.
__traversable_vec_traverse-- map fn over each element, collecting results into a new vec.
__alternative_vec_empty-- return a new empty vec (the zero element for alt-or).
__alternative_vec_alt_or-- return the concat function for two vecs.
__clone_vec_clone-- deep-copy a vec and all its int64_t elements.