Share your thoughts in the 2021 Clojure Community Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in Transducers by

In reducers, fold over a map has special support for kv. Consider whether/how to add this for transducers.

3 Answers

0 votes
by
_Comment made by: llasram_

We don't have a JIRA "unvote" feature, but I'd like to register my vote *against* this proposed enhancement.  As a heavy user of clojure.core.reducers, I consider the switch to k-v semantics when reducing a map to be a significant mis-feature.   As only an initial transformation function applied directly to a map is able to receive the k-v semantics (a limitation I can’t see how would not carry over to transducers), this behavior crops up most frequently when re-ordering operations and discovering that an intermediate map has now caused an airity error somewhere in the middle of a chain of threaded transformations.  I’ve never found cause to invoke it intentionally.
0 votes
by

Comment made by: gshayban

Marshall, there really isn't a proposed enhancement, yet. So there's nothing to be against! Your input is valuable. (Regarding c.c.reducers, that is a separate problem -- yes that behavior is surprising)

Considering kv-support for transducers:
Is it useful to have some functions that transform reduce-kv style reducing functions (fn (link: result k v))?

Ignore naming:
map-key
map-val
map-keyval
filter- * These could be mechanically generated. You wouldn't have to have a kv-version for every transducer currently in core. Some like map or filter could specifically apply to the key and ignore the val, or v.v.

Some things like map's transducer would be arity-incompatible (map's transducer has a varargs arity).

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1552 (reported by alexmiller)
...