How to update records in a ref map in Clojure?

Viewed 1652

Given the following scenario:

(defrecord Person [firstname lastname])
(def some-map (ref {}))

(dosync
  (alter some-map conj {1 (Person. "john" "doe")})
  (alter some-map conj {2 (Person. "jane" "jameson")}))

To change the firstname of "joe" to "nick", I do the following:

(dosync
  (alter some-map (fn [m]                   
                  (assoc m 1 
                       (assoc (m 1) :firstname "nick")))))

What is the idiomatic way of doing this in Clojure?

2 Answers
Related