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.
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)Removes consecutive duplicates, similar to
dedupe
.
Example:
(transduce-kv (dedupe-kv) tconj [11 11 22 22 22 33 33 33 33])
;; => [11 22 33]
Removes consecutive duplicates, similar to [`dedupe`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/dedupe) . Example: ```clojure (transduce-kv (dedupe-kv) tconj [11 11 22 22 22 33 33 33 33]) ;; => [11 22 33] ```
(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]
Returns elements with duplicates removed, similar to [`distinct`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/distinct) . Example: ```clojure (transduce-kv (distinct-kv) tconj [11 22 11 33 22 44 33 55 44]) ;; => [11 22 33 44 55] ```
(drop-kv n)Discards first n elements, similar to
drop
.
Example:
(transduce-kv (drop-kv 3) tconj [11 22 33 44 55])
;; => [44 55]
Discards first `n` elements, similar to [`drop`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/drop) . Example: ```clojure (transduce-kv (drop-kv 3) tconj [11 22 33 44 55]) ;; => [44 55] ```
(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]
Discards elements while `(pred keydex element)` returns truthy, similar to [`drop-while`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/drop-while) . Example: ```clojure (transduce-kv (drop-while-kv (fn [keydex _] (<= keydex 2))) tconj [11 22 33 44 55]) ;; => [44 55] ```
(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]
Returns elements separated by `sep`, similar to [`interpose`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/interpose) . Example: ```clojure (transduce-kv (interpose-kv :foo) tconj [11 22 33]) ;; => [11 :foo 22 :foo 33] ```
(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]]
Split into lists of `n` items each, may include fewer items than `n` at the end, similar to [`partition-all-kv`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/partition-all) . Example: ```clojure (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 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]]
Splits each time `(f keydex element)` returns a new value, similar to [`partition-by`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/partition-by) . Example: ```clojure (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 n)Retains the first n elements, similar to
take
.
Example:
(transduce-kv (take-kv 3) tconj [11 22 33 44 55])
;; => [11 22 33]
Retains the first `n` elements, similar to [`take`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/take) . Example: ```clojure (transduce-kv (take-kv 3) tconj [11 22 33 44 55]) ;; => [11 22 33] ```
(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]
Retains every `n`th element, similar to
[`take-nth`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/take-nth)
.
Example:
```clojure
(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 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]
Retains elements while `(pred keydex element)` is truthy, similar to
[`take-while`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/take-while)
.
Example:
```clojure
(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]
```cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |