Skip to content

Instantly share code, notes, and snippets.

@herdrick herdrick/gist:438610
Created Jun 15, 2010

What would you like to do?
(defn merge-general [m1 m2 f g]
(let [m1-only (difference (set (keys m1)) (set (keys m2)))
m2-only (difference (set (keys m2)) (set (keys m1)))]
(merge (merge-with f m1 m2)
(into {} (map (fn [k] [k (g (m1 k))]) m1-only))
(into {} (map (fn [k] [k (g (m2 k))]) m2-only)))))
user> (merge-general {:a 1, :b 2, :c 3} {:a 4, :b 5, :d 6} * sq)
{:d 36, :a 4, :b 10, :c 9}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.