Stateless, 'kv-ified' transducers. Safe to use with multi-threaded
brokvolli.multi/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.stateful-transducers-kv.
Stateless, 'kv-ified' transducers. Safe to use with multi-threaded [[brokvolli.multi/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.stateful-transducers-kv]].
(cat-kv rf)Concatenates the contents of input collection, similar to
cat.
Note: Unlike many other transducers in this namespace, cat-kv does not take
an explicit argument.
Example:
(transduce-kv cat-kv tconj [[11] [22] [33]])
;; => [11 22 33]
Concatenates the contents of input collection, similar to [`cat`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/cat). Note: Unlike many other transducers in this namespace, `cat-kv` does not take an explicit argument. Example: ```clojure (transduce-kv cat-kv tconj [[11] [22] [33]]) ;; => [11 22 33] ```
(filter-kv pred)Keeps only elements for which pred returns truthy, similar to
filter
. pred is a predicate of two arguments: key/index and next element.
Example:
(transduce-kv (filter-kv (fn [keydex x] (and (<= keydex 3)
(even? x))))
tconj
[11 22 33 44 55])
;; => [22 44]
Keeps only elements for which `pred` returns truthy, similar to
[`filter`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/filter)
. `pred` is a predicate of two arguments: key/index and next element.
Example:
```clojure
(transduce-kv (filter-kv (fn [keydex x] (and (<= keydex 3)
(even? x))))
tconj
[11 22 33 44 55])
;; => [22 44]
```(keep-kv f)Returns non-nil results of (f keydex value), similar to
keep
.
Example:
(transduce-kv (keep-kv (fn [keydex _] (even? keydex))) tconj [11 22 33 44 55])
;; => [true false true false true]
Returns non-`nil` results of `(f keydex value)`, similar to [`keep`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/keep) . Example: ```clojure (transduce-kv (keep-kv (fn [keydex _] (even? keydex))) tconj [11 22 33 44 55]) ;; => [true false true false true] ```
(map-kv f)Apply f to each input, similar to
map
. f is a function of two arguments: key/index and next element.
Note: This implementation subsumes map's multi-collection variadic arity.
Example:
(transduce-kv (map-kv (fn [keydex x] (vector (inc keydex) (* 10 x))))
tconj
[11 22 33])
;; => [[1 110] [2 220] [3 330]]
Apply `f` to each input, similar to
[`map`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/map)
. `f` is a function of two arguments: key/index and next element.
Note: This implementation subsumes `map`'s multi-collection variadic arity.
Example:
```clojure
(transduce-kv (map-kv (fn [keydex x] (vector (inc keydex) (* 10 x))))
tconj
[11 22 33])
;; => [[1 110] [2 220] [3 330]]
```(mapcat-kv f)Applies f to the inputs and concatenates the resulting collections, similar
to mapcat
. f is a function of key/index and the next value, and must return a collection.
Example:
(transduce-kv (mapcat-kv (fn [_ x] (repeat 3 x))) tconj [11 22 33])
;; => [11 11 11 22 22 22 33 33 33]
Applies `f` to the inputs and concatenates the resulting collections, similar to [`mapcat`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/mapcat) . `f` is a function of key/index and the next value, and must return a collection. Example: ```clojure (transduce-kv (mapcat-kv (fn [_ x] (repeat 3 x))) tconj [11 22 33]) ;; => [11 11 11 22 22 22 33 33 33] ```
(random-sample-kv prob)Returns elements as with
random-sample
.
Example:
(transduce-kv (random-sample-kv 0.5) tconj [11 22 33 44 55])
;; => [11 44]
;; different upon each evaluation...
Returns elements as with [`random-sample`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/random-sample) . Example: ```clojure (transduce-kv (random-sample-kv 0.5) tconj [11 22 33 44 55]) ;; => [11 44] ;; different upon each evaluation... ```
(remove-kv pred)Removes elements for which pred returns falsey, similar to
remove
. pred is a predicate of two arguments: key/index and next element.
Example:
(transduce-kv (remove-kv (fn [keydex _] (even? keydex))) tconj [11 22 33 44 55])
;; => [22 44]
Removes elements for which `pred` returns falsey, similar to [`remove`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/remove) . `pred` is a predicate of two arguments: key/index and next element. Example: ```clojure (transduce-kv (remove-kv (fn [keydex _] (even? keydex))) tconj [11 22 33 44 55]) ;; => [22 44] ```
(replace-kv smap)Given a hashmap of replacement pairs, replaces elements equal to the key
with corresponding value in smap, similar to
replace
.
Note: Unlike many other transducers in this namespace, replace-kv ignores
key/index.
Example:
(transduce-kv (replace-kv {11 :foo 33 :bar}) tconj [11 22 33 44 55])
;; => [:foo 22 :bar 44 55]
Given a hashmap of replacement pairs, replaces elements equal to the key
with corresponding value in `smap`, similar to
[`replace`](https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/replace)
.
Note: Unlike many other transducers in this namespace, `replace-kv` ignores
key/index.
Example:
```clojure
(transduce-kv (replace-kv {11 :foo 33 :bar}) tconj [11 22 33 44 55])
;; => [:foo 22 :bar 44 55]
```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 |