brokvolli.stateful-transducers-kv

Stateful, ‘kv-ified’ transducers. Not recommended for use with multi-threaded brokvolli.multi/transduce-kv.

Safe to use with single-threaded brokvolli.single/transduce-kv.

Each returns a transducer like their clojure.core namesakes, but with an additional arity-3 of result, keydex, and value. The bottom-level reducing function must also handle those three args.

See also brokvolli.transducers-kv.

dedupe-kv

(dedupe-kv)

Removes consecutive duplicates, similar to dedupe .

Example:

(transduce-kv (dedupe-kv) tconj [11 11 22 22 22 33 33 33 33])
;; => [11 22 33]

distinct-kv

(distinct-kv)

Returns elements with duplicates removed, similar to distinct .

Example:

(transduce-kv (distinct-kv) tconj [11 22 11 33 22 44 33 55 44])
;; => [11 22 33 44 55]

drop-kv

(drop-kv n)

Discards first n elements, similar to drop .

Example:

(transduce-kv (drop-kv 3) tconj [11 22 33 44 55])
;; => [44 55]

drop-while-kv

(drop-while-kv pred)

Discards elements while (pred keydex element) returns truthy, similar to drop-while .

Example:

(transduce-kv (drop-while-kv (fn [keydex _] (<= keydex 2))) tconj [11 22 33 44 55])
;; => [44 55]

interpose-kv

(interpose-kv sep)

Returns elements separated by sep, similar to interpose .

Example:

(transduce-kv (interpose-kv :foo) tconj [11 22 33])
;; => [11 :foo 22 :foo 33]

partition-all-kv

(partition-all-kv n)

Split into lists of n items each, may include fewer items than n at the end, similar to partition-all-kv .

Example:

(transduce-kv (partition-all-kv 3) tconj [11 22 33 44 55 66 77 88])
;; => [[11 22 33] [44 55 66] [77 88]]

partition-by-kv

(partition-by-kv f)

Splits each time (f keydex element) returns a new value, similar to partition-by .

Example:

(transduce-kv (partition-by-kv (fn [_ x] (even? x))) tconj [11 33 22 44 66 55 77 99 88])
;; => [[11 33] [22 44 66] [55 77 99] [88]]

take-kv

(take-kv n)

Retains the first n elements, similar to take .

Example:

(transduce-kv (take-kv 3) tconj [11 22 33 44 55])
;; => [11 22 33]

take-nth-kv

(take-nth-kv n)

Retains every nth element, similar to take-nth .

Example:

(transduce-kv (take-while-kv (fn [keydex x] (and (<= keydex 5)
                                                 (even? x))))
              tconj
              [11 22 33 44 55 66 77])
;; => [22 44 66]

take-while-kv

(take-while-kv pred)

Retains elements while (pred keydex element) is truthy, similar to take-while .

Example:

(transduce-kv (take-while-kv (fn [keydex x] (and (<= keydex 5)
                                                 (even? x))))
              tconj
              [11 22 33 44 55 66 77 88])
;; => [22 44 66]