tur/consume
seq-make-some
(seq-make-some [v :int] :int)
allocate Some(v) option.
seq-make-none
(seq-make-none :int)
seq-out-vec-new
(seq-out-vec-new :int)
allocate an empty vec (same layout as stdlib/vec.tur).
seq-out-vec-push!
(seq-out-vec-push! [v :int val :int] :void)
append val to the vec at v.
seq-make-cons
(seq-make-cons [val :int nxt :int] :int)
allocate a cons cell { value, next }.
seq-call-void-fn1
(seq-call-void-fn1 [f :int x :int] :void)
call a one-arg fat closure that returns void.
| f | fat closure (a -> void) | |
| x | argument |
Since: LZ3
seq/into-vec
(seq/into-vec [s :int] :int)
materialise a Seq into a growable vec.
| s | source Seq |
int64_t pointer to a heap vec containing all elements of s. Access with seq-vec-len and seq-vec-get (from stdlib/seq/core.tur).
(let [v (seq/into-vec (seq/range 0 3))]
(println (seq-vec-len v))) ; => 3
Since: LZ3
seq/into-list
(seq/into-list [s :int] :int)
materialise a Seq into a singly-linked list (head first).
| s | source Seq |
int64_t head pointer to a singly-linked list with the same element order as s. Iterate with seq-list-nil?, seq-list-head, seq-list-tail (from stdlib/seq/core.tur), or pass to seq-from-list.
(seq-for-each println (seq-from-list (seq/into-list (seq/range 0 3)))) ; => 0 1 2
Since: LZ3
seq/nth
(seq/nth [n :int s :int] :int)
return the element at 0-based position n, or None.
| n | 0-based index | |
| s | source Seq |
Some(element) if s has at least n+1 elements, else None.
(seq-opt-unwrap (seq/nth 2 (seq/range 10 15))) ; => 12
Since: LZ3
seq/first
(seq/first [s :int] :int)
return the first element of s, or None if s is empty.
| s | source Seq |
Some(first element) or None.
(seq-opt-unwrap (seq/first (seq/range 5 10))) ; => 5
Since: LZ3
seq/last
(seq/last [s :int] :int)
return the last element of s, or None if s is empty.
| s | source Seq |
Some(last element) or None.
(seq-opt-unwrap (seq/last (seq/range 5 10))) ; => 9
Since: LZ3
seq/count
(seq/count [s :int] :int)
count the number of elements in s.
| s | source Seq |
The total number of elements yielded by s.
(seq/count (seq/range 0 7)) ; => 7
Since: LZ3
seq/reduce
(seq/reduce [f :int s :int] :int)
fold s with f, no initial value; returns None if s is empty.
| f | fat closure (a a -> a) combining accumulator and next element | |
| s | source Seq |
Some(result) after applying f left-associatively across all elements, or None if s is empty.
(let [zero 0 sum (fn [a b] (let [_ zero] (+ a b)))]
(seq-opt-unwrap (seq/reduce sum (seq/range 1 5)))) ; => 10
Since: LZ3
seq/foldl
(seq/foldl [init :int f :int s :int] :int)
fold s left with f starting from init.
| init | initial accumulator value | |
| f | fat closure (b a -> b) combining accumulator and next element | |
| s | source Seq |
The final accumulator after applying f to each element of s.
(let [zero 0 sum (fn [a b] (let [_ zero] (+ a b)))]
(seq/foldl zero sum (seq/range 1 5))) ; => 10
Since: LZ3
seq/for-each
(seq/for-each [f :int s :int] :void)
call f on every element of s for side effects.
| f | fat closure (a -> void) called with each element | |
| s | source Seq |
(let [zero 0 f (fn [x] (let [_ zero] (println x)))]
(seq/for-each f (seq/range 0 3))) ; prints 0 1 2
Since: LZ3
seq/any?
(seq/any? [pred :int s :int] :bool)
return true if pred holds for at least one element; short-circuits.
| pred | fat closure (a -> bool) | |
| s | source Seq |
true as soon as pred(x) is true; false if no element satisfies pred.
(let [five 5 eq5? (fn [x] (= x five))]
(seq/any? eq5? (seq/range 0 10))) ; => true
Since: LZ3
seq/all?
(seq/all? [pred :int s :int] :bool)
return true if pred holds for every element; short-circuits on first failure.
| pred | fat closure (a -> bool) | |
| s | source Seq |
false as soon as pred(x) is false; true if every element satisfies pred.
(let [ten 10 small? (fn [x] (< x ten))]
(seq/all? small? (seq/range 0 10))) ; => true
Since: LZ3
seq/find
(seq/find [pred :int s :int] :int)
return the first element satisfying pred, or None.
| pred | fat closure (a -> bool) | |
| s | source Seq |
Some(first matching element), or None if no element satisfies pred.
(let [six 6 big? (fn [x] (> x six))]
(seq-opt-unwrap (seq/find big? (seq/range 0 10)))) ; => 7
Since: LZ3
seq/find-index
(seq/find-index [pred :int s :int] :int)
return the 0-based index of the first element satisfying pred, or None.
| pred | fat closure (a -> bool) | |
| s | source Seq |
Some(index) of the first matching element, or None.
(let [six 6 big? (fn [x] (> x six))]
(seq-opt-unwrap (seq/find-index big? (seq/range 0 10)))) ; => 7
Since: LZ3