Skip to content

Instantly share code, notes, and snippets.

@amalloy

amalloy/sets.clj Secret

Created November 16, 2010 22:52
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 amalloy/0557059ea1585b322cec to your computer and use it in GitHub Desktop.
Save amalloy/0557059ea1585b322cec to your computer and use it in GitHub Desktop.
user> sets
[#{:a :c :b} #{:c :d} #{:f :e}]
user> (reduce (fn [curr new]
(if-let [match (first (filter #(some new %) curr))]
(map #(if (= match %)
(union new %)
%)
curr)
(conj curr new)))
[] sets)
(#{:f :e} #{:a :c :b :d})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment