Created
July 10, 2017 22:59
-
-
Save Frozenlock/8b6769128c54b1b27c7b6878989d1ee0 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
(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