How to Increment Values in a Map

clojure, immutability, state

Solution

Just produce a new map and use it:

(def m {:a 3 :b 4})

(apply merge 
  (map (fn [[k v]] {k (inc v) }) m))

; {:b 5, :a 4}

Problem

I am wrapping my head around state in Clojure. I come from languages where state can be mutated. For example, in Python, I can create a dictionary, put some string => integer pairs inside, and then walk over the dictionary and increment the values. How would I do this in idiomatic Clojure?

Original source

Related problems