Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created November 28, 2013 10:38
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 jballanc/7690023 to your computer and use it in GitHub Desktop.
Save jballanc/7690023 to your computer and use it in GitHub Desktop.
Compare nested maps
(defn comp-map [ma mb]
(reduce (fn [a [k v]]
(and a
(if (and (map? v) (map? (mb k)))
(comp-map v (mb k))
(= v (mb k)))))
true
ma))
(comp-map {:a {:b 2 :c 3}} {:a {:b 2 :c 3}})) ;=> true
(comp-map {:a {:b 2 :c 3}} {:a {:b 2 :c 4}})) ;=> false
(comp-map {:a {:b 2 :c 3}} {:a {:b 2 :c 3 :d 4} :e 5})) ;=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment