tur/builders
seq-call-fn0
(seq-call-fn0 [f :int] :int)
call a zero-arg fat closure stored as int64_t.
seq-call-fn1
(seq-call-fn1 [f :int x :int] :int)
seq-opt-some?
(seq-opt-some? [o :int] :bool)
test whether an option value is non-NULL (some).
seq-opt-unwrap
(seq-opt-unwrap [o :int] :int)
seq-pair-first
(seq-pair-first [p :int] :int)
return the first element of a Tuple2 (legacy name).
seq-pair-second
(seq-pair-second [p :int] :int)
seq/range
(seq/range [start :int end :int] :int)
half-open integer range [start, end).
| start | inclusive lower bound | |
| end | exclusive upper bound |
A Seq yielding start, start+1, ..., end-1. Empty if start >= end.
(seq/range 0 5) ; => 0 1 2 3 4
Since: LZ1
seq/range-step
(seq/range-step [start :int end :int step :int] :int)
integer range with a custom step.
| start | inclusive start value | |
| end | exclusive end value (for positive step) or lower bound (negative) | |
| step | increment per element (must not be zero) |
A Seq yielding start, start+step, start+2*step, ... stopping before end (positive step) or before going below end (negative step).
(seq/range-step 0 10 2) ; => 0 2 4 6 8 (seq/range-step 10 0 -3) ; => 10 7 4 1
Since: LZ1
seq/repeat
(seq/repeat [v :int] :int)
infinite sequence repeating a single value.
| v | the value to repeat indefinitely |
An infinite Seq always yielding v. Use seq-nth or a bounded iteration to consume.
(seq/repeat 42) ; => 42 42 42 ...
Since: LZ1
seq/repeatedly
(seq/repeatedly [f :int] :int)
infinite sequence from repeated zero-arg function calls.
| f | a zero-arg fat closure called to produce each element |
An infinite Seq yielding (f), (f), (f), ...
(let [counter (ref 0)]
(seq/repeatedly (fn [] (let [v @counter] (set-ref! counter (+ v 1)) v))))
Since: LZ1
seq/cycle
(seq/cycle [s :int] :int)
infinite sequence cycling over a finite Seq.
| s | a finite Seq to cycle |
An infinite Seq repeating the elements of s. Returns empty-seq if s is itself empty.
(seq/cycle (seq/range 0 3)) ; => 0 1 2 0 1 2 0 1 2 ...
Since: LZ1
seq/iterate
(seq/iterate [init :int f :int] :int)
infinite sequence x, f(x), f(f(x)), ...
| init | seed value | |
| f | one-arg fat closure applied to produce the next element |
A Seq yielding init, f(init), f(f(init)), ...
(seq/iterate 1 (fn [x] (* x 2))) ; => 1 2 4 8 16 ...
Since: LZ1
seq/unfold
(seq/unfold [seed :int f :int] :int)
build a Seq by unfolding from a seed value.
| seed | initial seed value | |
| f | one-arg fat closure: seed -> (option (pair value next-seed)) | |
| return none to terminate the sequence |
A Seq yielding the first element of each pair until f returns none.
(seq/unfold 0 (fn [n]
(if (< n 5) (some (pair-new n (+ n 1))) (none))))
; => 0 1 2 3 4
Since: LZ1