aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clojure/contrib/map_utils.clj15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/clojure/contrib/map_utils.clj b/src/clojure/contrib/map_utils.clj
index 58ab03bc..3862fcee 100644
--- a/src/clojure/contrib/map_utils.clj
+++ b/src/clojure/contrib/map_utils.clj
@@ -34,4 +34,19 @@
[map ks]
(reduce safe-get map ks))
+; by Chouser:
+(defn deep-merge-with
+ "Like merge-with, but merges maps recursively, appling the given fn
+ only when there's a non-map at a particular level.
+
+ (deepmerge + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4}
+ {:a {:b {:c 2 :d {:z 9} :z 3} :e 100}})
+ -> {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}"
+ [f & maps]
+ (apply
+ (fn m [& maps]
+ (if (every? map? maps)
+ (apply merge-with m maps)
+ (apply f maps)))
+ maps))