No matching definitions.

tur/consume

stdlib/seq/consume.tur
defn

seq-make-some

(seq-make-some [v :int] :int)

allocate Some(v) option.

defn

seq-make-none

(seq-make-none :int)
defn

seq-out-vec-new

(seq-out-vec-new :int)

allocate an empty vec (same layout as stdlib/vec.tur).

defn

seq-out-vec-push!

(seq-out-vec-push! [v :int val :int] :void)

append val to the vec at v.

defn

seq-make-cons

(seq-make-cons [val :int nxt :int] :int)

allocate a cons cell { value, next }.

defn

seq-call-void-fn1

(seq-call-void-fn1 [f :int x :int] :void)

call a one-arg fat closure that returns void.

ffat closure (a -> void)
xargument

Since: LZ3

defn

seq/into-vec

(seq/into-vec [s :int] :int)

materialise a Seq into a growable vec.

ssource 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

defn

seq/into-list

(seq/into-list [s :int] :int)

materialise a Seq into a singly-linked list (head first).

ssource 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

defn

seq/nth

(seq/nth [n :int s :int] :int)

return the element at 0-based position n, or None.

n0-based index
ssource 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

defn

seq/first

(seq/first [s :int] :int)

return the first element of s, or None if s is empty.

ssource Seq

Some(first element) or None.

(seq-opt-unwrap (seq/first (seq/range 5 10)))  ; => 5

Since: LZ3

defn

seq/last

(seq/last [s :int] :int)

return the last element of s, or None if s is empty.

ssource Seq

Some(last element) or None.

(seq-opt-unwrap (seq/last (seq/range 5 10)))  ; => 9

Since: LZ3

defn

seq/count

(seq/count [s :int] :int)

count the number of elements in s.

ssource Seq

The total number of elements yielded by s.

(seq/count (seq/range 0 7))  ; => 7

Since: LZ3

defn

seq/reduce

(seq/reduce [f :int s :int] :int)

fold s with f, no initial value; returns None if s is empty.

ffat closure (a a -> a) combining accumulator and next element
ssource 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

defn

seq/foldl

(seq/foldl [init :int f :int s :int] :int)

fold s left with f starting from init.

initinitial accumulator value
ffat closure (b a -> b) combining accumulator and next element
ssource 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

defn

seq/for-each

(seq/for-each [f :int s :int] :void)

call f on every element of s for side effects.

ffat closure (a -> void) called with each element
ssource 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

defn

seq/any?

(seq/any? [pred :int s :int] :bool)

return true if pred holds for at least one element; short-circuits.

predfat closure (a -> bool)
ssource 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

defn

seq/all?

(seq/all? [pred :int s :int] :bool)

return true if pred holds for every element; short-circuits on first failure.

predfat closure (a -> bool)
ssource 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

defn

seq/find

(seq/find [pred :int s :int] :int)

return the first element satisfying pred, or None.

predfat closure (a -> bool)
ssource 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

defn

seq/find-index

(seq/find-index [pred :int s :int] :int)

return the 0-based index of the first element satisfying pred, or None.

predfat closure (a -> bool)
ssource 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