Last active
January 22, 2016 17:21
-
-
Save ponzao/634c7add8014bf6fcdff to your computer and use it in GitHub Desktop.
This file contains hidden or 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 merge-with-key | |
[f & maps] | |
(when (some identity maps) | |
(reduce (fn [acc x] | |
(reduce (fn [m [k v]] | |
(if (contains? m k) | |
(assoc m k (f k (get m k) v)) | |
(assoc m k v))) | |
acc | |
x)) | |
maps))) | |
(defn deep-merge-with-key | |
[f & maps] | |
(apply | |
(fn m [& maps] | |
(let [[k & args] maps] | |
(cond (every? map? maps) (apply merge-with-key m maps) | |
(every? map? args) (apply merge-with-key m args) | |
:else (apply f k args)))) | |
maps)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment