Add `utils/deep-merge`

This commit is contained in:
Peter Taoussanis 2012-10-19 15:05:24 +07:00
parent 5750fc7c8b
commit dc995c10ad
2 changed files with 23 additions and 2 deletions

View File

@ -32,7 +32,8 @@
Other keys include: :instant, :timestamp, :hostname, :ns, :error?
See source code for examples."}
See source code for examples and `utils/deep-merge` for a convenient way
to reconfigure appenders."}
(atom {:current-level :debug
;;; Control log filtering by namespace patterns (e.g. ["my-app.*"]).

View File

@ -14,4 +14,24 @@
@d-result
(let [d-result (delay (apply f args))]
(swap! cache assoc args {:time-cached now :d-result d-result})
@d-result))))))
@d-result))))))
(defn deep-merge-with ; From clojure.contrib.map-utils
"Like `merge-with` but merges maps recursively, applying the given fn
only when there's a non-map at a particular level.
(deepmerge-with + {: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))
(defn deep-merge
"Partial of `deep-merge-with`."
[& maps]
(apply deep-merge-with (fn [x y] y) maps))