tur/vec
vec-new
(vec-new)
allocate a new empty vec.
Since: Phase B1
vec-len
(vec-len [v] :int)
return the number of elements in a vec.
| v | vec pointer returned by vec-new |
Since: Phase B1
vec-get
(vec-get [v i] :int)
return the element at index i (bounds-checked).
| v | vec pointer | |
| i | zero-based index |
Since: Phase B1
vec-push!
(vec-push! [v val])
append a value to the end of a vec, growing storage as needed.
| v | vec pointer | |
| val | value to append |
Since: Phase B1
vec-pop!
(vec-pop! [v] :int)
remove and return the last element of a vec.
| v | vec pointer (must be non-empty) |
Since: Phase B1
vec-free
(vec-free [v])
free a vec and its backing data buffer.
| v | vec pointer to free |
Since: Phase B1
Functor[vec]
(definstance Functor [vec])
fmap applies a function to every element, returning a new vec.
Foldable[vec]
(definstance Foldable [vec])
foldl and foldr fold a vec with an accumulator function.
Applicative[vec]
(definstance Applicative [vec])
pure wraps a value; ap applies each function to each value.
Monad[vec]
(definstance Monad [vec])
bind maps fn over each element and flattens the results.
Traversable[vec]
(definstance Traversable [vec])
traverse maps an effectful function over a vec, collecting results.
Alternative[vec]
(definstance Alternative [vec])
empty returns []; alt-or concatenates two vecs.
vec-eq?
(vec-eq? [v1 v2 cmp-fn] :bool)
compare two vecs element-wise using a comparator function.
| v1 | first vec pointer | |
| v2 | second vec pointer | |
| cmp-fn | comparator fn [a :int b :int] :bool applied to each element pair |
Since: Phase E1
Eq[vec]
(definstance Eq [vec])
eq? compares two vecs using integer equality on each element.
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.