Skip to content

Instantly share code, notes, and snippets.

@herdrick
Created June 15, 2010 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herdrick/438610 to your computer and use it in GitHub Desktop.
Save herdrick/438610 to your computer and use it in GitHub Desktop.
(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