assoc-in

functionsince v0.0-927 clojure.core/assoc-inEdit
(assoc-in m [k & ks] v)

Details:

Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value. Returns a new nested structure.

If any levels do not exist, hash-maps will be created.


Examples:

(def users [{:name "James" :age 26}
            {:name "John" :age 43}])

Update the age of the second (index 1) user:

(assoc-in users [1 :age] 44)
;;=> [{:name "James", :age 26}
;;    {:name "John", :age 44}]

Insert the password of the second (index 1) user:

(assoc-in users [1 :password] "nhoJ")
;;=> [{:name "James", :age 26}
;;    {:password "nhoJ", :name "John", :age 43}]

See Also:


Source docstring:
Associates a value in a nested associative structure, where ks is a
sequence of keys and v is the new value and returns a new nested structure.
If any levels do not exist, hash-maps will be created.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn assoc-in
  [m [k & ks] v]
  (if ks
    (assoc m k (assoc-in (get m k) ks v))
    (assoc m k v)))