Skip to content

Instantly share code, notes, and snippets.

@frenchy64
Last active August 29, 2015 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frenchy64/485bd7705da61472dba9 to your computer and use it in GitHub Desktop.
Save frenchy64/485bd7705da61472dba9 to your computer and use it in GitHub Desktop.
(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