You're viewing version 1.2.0 of intersection. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16



  • (intersection s1)
  • (intersection s1 s2)
  • (intersection s1 s2 & sets)
Return a set that is the intersection of the input sets

1 Example top

  • user=> (intersection #{1})
    user=> (intersection #{1 2} #{2 3})
    user=> (intersection #{1 2} #{2 3} #{3 4})
    user=> (intersection #{1 :a} #{:a 3} #{:a})
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/set.clj:32 top

(defn intersection
  "Return a set that is the intersection of the input sets"
  {:added "1.0"}
  ([s1] s1)
  ([s1 s2]
     (if (< (count s2) (count s1))
       (recur s2 s1)
       (reduce (fn [result item]
                   (if (contains? s2 item)
                     (disj result item)))
	       s1 s1)))
  ([s1 s2 & sets] 
     (let [bubbled-sets (bubble-max-key #(- (count %)) (conj sets s2 s1))]
       (reduce intersection (first bubbled-sets) (rest bubbled-sets)))))
Vars in clojure.set/intersection: < contains? count defn disj first fn let reduce rest
Used in 0 other vars

Comments top

No comments for intersection. Log in to add a comment.