Skip to content

Instantly share code, notes, and snippets.

@Frozenlock
Created July 10, 2017 22:59
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 Frozenlock/8b6769128c54b1b27c7b6878989d1ee0 to your computer and use it in GitHub Desktop.
Save Frozenlock/8b6769128c54b1b27c7b6878989d1ee0 to your computer and use it in GitHub Desktop.
(defn deep-merge
"Recursively merges maps. If vals are not maps, the last value wins."
[& vals]
(if (every? map? vals)
(apply merge-with deep-merge vals)
(last vals)))
(defn deep-merge-with
"Like merge-with, but merges maps recursively, applying the given fn
only when there's a non-map at a particular level."
[f & maps]
(apply
(fn m [& maps]
(if (every? map? maps)
(apply merge-with m maps)
(apply f maps)))
maps))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment