merge-with

functionsince v0.0-927 clojure.core/merge-withEdit
(merge-with f & maps)

Details:

Returns a map that consists of the rest of the maps conj-ed onto the first.

If a key occurs in more than one map, the mapping(s) from the latter (left-to- right) will be combined with the mapping in the result by calling (f val-in- result val-in-latter).


See Also:


Source docstring:
Returns a map that consists of the rest of the maps conj-ed onto
the first.  If a key occurs in more than one map, the mapping(s)
from the latter (left-to-right) will be combined with the mapping in
the result by calling (f val-in-result val-in-latter).
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn merge-with
  [f & maps]
  (when (some identity maps)
    (let [merge-entry (fn [m e]
                        (let [k (key e) v (val e)]
                          (if (contains? m k)
                            (assoc m k (f (get m k) v))
                            (assoc m k v))))
          merge2 (fn [m1 m2]
                   (reduce merge-entry (or m1 {}) (seq m2)))]
      (reduce merge2 maps))))