Fork me on GitHub
#beginners
<
2019-10-19
>
dharrigan13:10:16

Is there a better way to do this? (into {} (map (fn [[k v]] {k (clojure.string/upper-case v)}) parsed)) (I only want the values uppercased)?

bfabry14:10:48

specter is also very good at this kind of thing if you want to go the library route

bfabry14:10:08

concretely

cljs.user=> (reduce-kv (fn [m k v] (assoc m k (clojure.string/upper-case v))) {} {:a "foo"})
{:a "FOO"}

bfabry14:10:25

for really marginal values of “better”

schmee15:10:08

Specter would look like this:

(transform MAP-VALS s/upper-case parsed)

dharrigan16:10:23

Ah, I should have been clearer. No 3rd party deps 🙂 Just core language constructs 🙂

dharrigan16:10:29

But reduced-kv does brilliantly, thanks bfabry!

dharrigan16:10:34

(reduce-kv (fn [x y z] (assoc x y (clojure.string/upper-case z))) {} parsed)

seancorfield19:10:26

There's been some discussion of possibly adding map-keys and/or map-vals for this sort of thing, in Clojure 1.11...

seancorfield19:10:46

(map-vals str/upper-case parsed)