Last active
August 29, 2015 14:12
-
-
Save frenchy64/485bd7705da61472dba9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro update-in* | |
"'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." | |
([m [k & ks] f & args] | |
(if ks | |
`(let [m# ~m k# ~k] (assoc m# k# (update-in* (get m# k#) ~ks ~f ~@args))) | |
`(let [m# ~m k# ~k] (assoc m# k# (~f (get m# k#) ~@args)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment