Search code examples
clojure

How to update map value using function?


I have a map m, a key k and a function f. Is it possible to rewrite this code simpler?

(assoc m k (f (get m k))

Solution

  • Try clojure.core/update-in

    (update-in m [k] f)
    

    Edit: Clojure 1.7 introduced clojure.core/update

    (update m k f)