I want to transform one map of values to another map with the same keys but with a function applied to the values. I would think there was a function for doing this in the c
I'm wondering why nobody has mentioned the specter library yet. It has been written to make this kind of transform easy to code (and, even more important, the written code easy to understand), while still being very performant:
(require '[com.rpl.specter :as specter])
(defn map-vals [m f]
(specter/transform
[specter/ALL specter/LAST]
f m))
(map-vals {:a "test" :b "testing"}
#(.toUpperCase %))
Writing such a function in pure Clojure is simple, but the code gets much trickier once you move on to highly nested code composed of different data structures. And this is where specter comes in.
I recommend watching this episode on Clojure TV which explains the motivation behind and details of specter.