Skip to content

Instantly share code, notes, and snippets.

@magnars
Created August 21, 2014 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnars/006152e52fe740749799 to your computer and use it in GitHub Desktop.
Save magnars/006152e52fe740749799 to your computer and use it in GitHub Desktop.
(defn update-in* [m path f]
"Like update-in, but can map over lists by nesting paths."
(if (vector? (last path))
(let [nested-path (last path)
this-path (drop-last path)]
(if (empty? nested-path)
(update-in m this-path (partial map f))
(update-in m this-path (partial map #(update-in* % nested-path f)))))
(update-in m path f)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment