(update-in m [k & ks] f)
(update-in m [k & ks] f a)
(update-in m [k & ks] f a b)
(update-in m [k & ks] f a b c)
(update-in m [k & ks] f a b c & args)
'Updates' a value in a nested associative structure, where ks is a
sequence of keys and f is a function that will take the old value
and any supplied args and return the new value, and returns a new
nested structure. If any levels do not exist, hash-maps will be
created.
Source
(defn
update-in
"'Updates' a value in a nested associative structure, where ks is a\n sequence of keys and f is a function that will take the old value\n and any supplied args and return the new value, and returns a new\n nested structure. If any levels do not exist, hash-maps will be\n created."
([m [k & ks] f]
(if
ks
(assoc m k (update-in (get m k) ks f))
(assoc m k (f (get m k)))))
([m [k & ks] f a]
(if
ks
(assoc m k (update-in (get m k) ks f a))
(assoc m k (f (get m k) a))))
([m [k & ks] f a b]
(if
ks
(assoc m k (update-in (get m k) ks f a b))
(assoc m k (f (get m k) a b))))
([m [k & ks] f a b c]
(if
ks
(assoc m k (update-in (get m k) ks f a b c))
(assoc m k (f (get m k) a b c))))
([m [k & ks] f a b c & args]
(if
ks
(assoc m k (apply update-in (get m k) ks f a b c args))
(assoc m k (apply f (get m k) a b c args)))))