union

added
1.0

ns
clojure.set

type
function

(union) (union s1) (union s1 s2) (union s1 s2 & sets)

Return a set that is the union of the input sets

                user=> (union)
#{}

user=> (union #{1 2})
#{1 2}

user=> (union #{1 2} #{2 3})
#{1 2 3}

user=> (union #{1 2} #{2 3} #{3 4})
#{1 2 3 4}

            
                (reduce (fn [flattened [key val]]
          (conj flattened val))
        #{}
        {:e #{:m :f}, :c #{:f}, :b #{:c :f}, :d #{:m :f}, :a #{:c :f}})

;;=> #{#{:m :f} #{:c :f} #{:f}}


(reduce (fn [flattened [key val]]
          (clojure.set/union flattened val))
        #{}
        {:e #{:m :f}, :c #{:f}, :b #{:c :f}, :d #{:m :f}, :a #{:c :f}})

;;=> #{:m :c :f}
            
                (defn flatten-dpdnts [dpdnts-map]
  (apply set/union (vals dpdnts-map)))

(flatten-dpdnts {:e #{:m :f}, :c #{:f}, :b #{:c :f}, :d #{:m :f}, :a #{:c :f}})
;;=> #{:m :c :f}