mirror of https://github.com/status-im/timbre.git
Add `utils/deep-merge`
This commit is contained in:
parent
5750fc7c8b
commit
dc995c10ad
|
@ -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.*"]).
|
||||
|
|
|
@ -15,3 +15,23 @@
|
|||
(let [d-result (delay (apply f args))]
|
||||
(swap! cache assoc args {:time-cached now :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))
|
Loading…
Reference in New Issue