Mapping a function on the values of a map in Clojure

前端 未结 11 1470
面向向阳花
面向向阳花 2020-11-29 16:03

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

11条回答
  •  再見小時候
    2020-11-29 16:30

    I like your reduce version just fine. I think it's idiomatic. Here's a version using list comprehension anyways.

    (defn foo [m f]
      (into {} (for [[k v] m] [k (f v)])))
    

提交回复
热议问题