aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/map_utils.clj
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2009-03-19 20:38:31 +0000
committerChouser <chouser@n01se.net>2009-03-19 20:38:31 +0000
commit19613025d233b5f445b1dd3460c4128f39218741 (patch)
treecee469c325e69243cf2fcddcb4a2c62e98ed506e /src/clojure/contrib/map_utils.clj
parentd94d82fefc2208316bdf759febe576ab046c9404 (diff)
map-utils: add deep-merge-with
Diffstat (limited to 'src/clojure/contrib/map_utils.clj')
-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))