tur/transform
seq-call-bool-fn1
(seq-call-bool-fn1 [f :int x :int] :bool)
call a one-arg fat closure that returns bool.
| f | fat closure (int64_t): (a -> bool) | |
| x | argument |
bool result of calling f(x).
Since: LZ2
seq-call-fn2
(seq-call-fn2 [f :int x :int y :int] :int)
call a two-arg fat closure stored as int64_t.
| f | fat closure (int64_t): (a b -> c) | |
| x | first argument | |
| y | second argument |
int64_t result of calling f(x, y).
Since: LZ2
seq-gen-to-int
(seq-gen-to-int [g :ptr<void>] :int)
cast a void* generator pointer to int64_t.
seq-gen-from-int
(seq-gen-from-int [i :int] :ptr<void>)
seq-gen-done-int
(seq-gen-done-int [i :int] :bool)
seq-gen-next-int
(seq-gen-next-int [i :int] :ptr<void>)
seq/map
(seq/map [f :int s :int] :int)
apply f to every element of s, yielding the results.
| f | fat closure (a -> b) applied to each element | |
| s | source Seq |
A lazy Seq yielding f(x) for each x in s.
(let [two 2 double (fn [x] (* x two))]
(seq-for-each println (seq/map double (seq/range 0 4))))
; => 0 2 4 6
Since: LZ2
seq/filter
(seq/filter [pred :int s :int] :int)
yield only elements of s for which pred returns true.
| pred | fat closure (a -> bool) tested on each element | |
| s | source Seq |
A lazy Seq yielding each x in s where pred(x) is true.
(let [two 2 even? (fn [x] (= (mod x two) 0))]
(seq-for-each println (seq/filter even? (seq/range 0 6))))
; => 0 2 4
Since: LZ2
seq/take
(seq/take [n :int s :int] :int)
yield at most n elements from s.
| n | maximum number of elements to yield | |
| s | source Seq |
A Seq yielding the first n elements of s (fewer if s is shorter).
(seq-for-each println (seq/take 3 (seq/range 0 10))) ; => 0 1 2
Since: LZ2
seq/drop
(seq/drop [n :int s :int] :int)
skip the first n elements of s, then yield the rest.
| n | number of elements to skip | |
| s | source Seq |
A Seq that skips the first n elements of s and yields the remainder.
(seq-for-each println (seq/drop 2 (seq/range 0 5))) ; => 2 3 4
Since: LZ2
seq/take-while
(seq/take-while [pred :int s :int] :int)
yield elements from s while pred holds; stop on first failure.
| pred | fat closure (a -> bool) tested on each element | |
| s | source Seq |
A Seq yielding a prefix of s up to (not including) the first element for which pred returns false.
(let [ten 10 small? (fn [x] (< x ten))]
(seq-for-each println (seq/take-while small? (seq/range 0 15))))
; => 0 1 2 3 4 5 6 7 8 9
Since: LZ2
seq/drop-while
(seq/drop-while [pred :int s :int] :int)
skip leading elements of s while pred holds; yield the rest.
| pred | fat closure (a -> bool) tested on each element | |
| s | source Seq |
A Seq that drops the leading prefix of s satisfying pred, then yields all remaining elements.
(let [ten 10 small? (fn [x] (< x ten))]
(seq-for-each println (seq/drop-while small? (seq/range 8 13))))
; => 10 11 12
Since: LZ2
seq/map-indexed
(seq/map-indexed [f :int s :int] :int)
like seq/map but also passes the 0-based element index to f.
| f | fat closure (int a -> b) called with (index, element) | |
| s | source Seq |
A Seq yielding f(0, x0), f(1, x1), f(2, x2), ...
(let [ten 10 f (fn [i x] (let [_ ten] (+ (* i ten) x)))]
(seq-for-each println (seq/map-indexed f (seq/range 5 8))))
; => 5 16 27
Since: LZ2
seq/filter-map
(seq/filter-map [f :int s :int] :int)
map and filter in a single pass.
| f | fat closure (a -> option) returning Some(b) to keep or None to skip | |
| s | source Seq |
A Seq yielding the unwrapped Some values returned by f, skipping None.
;; keep only even numbers doubled
(let [two 2
f (fn [x] (if (= (mod x two) 0) (make-some (* x two)) (make-none)))]
(seq-for-each println (seq/filter-map f (seq/range 0 6))))
; => 0 4 8
Since: LZ2
seq/flat-map
(seq/flat-map [f :int s :int] :int)
map each element to a Seq and yield all elements of each.
| f | fat closure (a -> Seq b) applied to each element | |
| s | source Seq |
A Seq that yields all elements of f(x0), then all of f(x1), etc.
(let [two 2 f (fn [x] (seq/range 0 (+ x two)))]
(seq-for-each println (seq/flat-map f (seq/range 0 3))))
; => 0 1 0 1 2 0 1 2 3
Since: LZ2
seq/flatten
(seq/flatten [s :int] :int)
yield all elements of each inner Seq in a Seq of Seqs.
| s | a Seq whose elements are themselves Seqs (as int64_t pointers) |
A Seq yielding all elements of the inner Seqs in order.
(let [s (seq-of (seq/range 1 3))]
(seq-for-each println (seq/flatten s)))
; => 1 2
Since: LZ2