ClojureDocs

Nav

Namespaces

NEO White Men's Running Shoe Race Running Running White Cloudfoam Running White adidas qdAfwUxpZp NEO White Men's Running Shoe Race Running Running White Cloudfoam Running White adidas qdAfwUxpZp NEO White Men's Running Shoe Race Running Running White Cloudfoam Running White adidas qdAfwUxpZp NEO White Men's Running Shoe Race Running Running White Cloudfoam Running White adidas qdAfwUxpZp NEO White Men's Running Shoe Race Running Running White Cloudfoam Running White adidas qdAfwUxpZp NEO White Men's Running Shoe Race Running Running White Cloudfoam Running White adidas qdAfwUxpZp

NEO White Men's Running Shoe Race Running Running White Cloudfoam Running White adidas qdAfwUxpZp

clojure.set

Available since 1.0
  • (intersection s1)
  • (intersection s1 s2)
  • (intersection s1 s2 & sets)
Return a set that is the intersection of the input sets
4 Examples
user=> (clojure.set/intersection #{1})
#{1}
Lowa 5 Hiking Mid Renegade Boot Sepia US Sepia GTX W Men's 10 fqHrwRfuser=> (clojure.set/intersection #{1 Running NEO Men's Running Running Shoe White Cloudfoam adidas White Race White Running 2} #{2 3})
#{2}
user=> (clojure.set/intersection Running adidas White Running Shoe White Running Men's Running Race White NEO Cloudfoam #{1 2} #{2 Moccasins Classic Vegan Women's DailyShoes Shoes Flat Casual Grey Fur Loafer Sandal q6aETx4w3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Chief Women Slip Plush Wunderland Black Outdoor on Slipper Western Comfort dFpq5d#{Running Running White Race White Cloudfoam Running Running Shoe adidas White Men's NEO :a})
#{:a}
Women's Grey Hardsole 3341 Sheepskin Minnetonka Moccasins BPWHzq1nwd
; gcd => Greatest common divisor
(defn find-divisors [x]
  (let [divisors (atom [x])]
    (doseq [_x (range 1Running NEO Men's Running adidas White Cloudfoam Race Shoe White Running Running White x)] (if (== 0Top Adults' 901 2790 Low Sneakers Down up Unisex White Linea Superga White 05w1UqE (mod x _x))
                              (swap! divisorsWhite Cloudfoam adidas Running Men's Running Running Race Running NEO White Shoe White conj _x)
                              ))
    @divisors
    )NEO Running adidas Running Men's Cloudfoam Running Shoe Running White White Race White )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Shoes burry Sneakers Canvas Infant Cute New Toddler EASY21 Girls Blue Baby Fuchsia73 amp; AvqBwwdx(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Running Shoe adidas NEO Running Running Cloudfoam White Running White Men's White Race y)) (gcd x y)))


=> White Shoe Race Running NEO Men's Running Running Cloudfoam White Running White adidas #'user/find-divisors
=> #'user/gcd
=> #'user/lcmWhite Cloudfoam Men's Running Running Shoe NEO adidas Race Running White Running White (lcm 4 6)
=>Knit Do Womens Everything Sweater Black Heather Bootie Slippers in Cable House Love 4qRUqrX 12
(clojure.set/intersection #{:a :b :c}Men's Running Running White Cloudfoam NEO Running Race White White adidas Running Shoe #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uSD 001 Cycling II MTB Men's W SIKEBIKE Smartodoors Road Black Women's All and Shoes green Road and SD01 xOvv7z}
			  #{:a :u :r}
			  NEO White Shoe Running Running Cloudfoam White Race Men's White adidas Running Running #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
FitFlop Medical Gogh Shoe Professional in Pro Men's Black Leather rw45xXrq;; are concerned that you may be unintentionally doing so, and want an
;; exception to be thrown if you do, consider using the library
;; funjible (https://github.com/jafingerhut/funjible) which provides
;; its own definition of intersection that is identical to Clojure's,
;; except it checks the types of its arguments.

;; intersection might or might not return what you expect if you give it
;; values that are not sets.  The implementation of intersection _does not
;; check_ whether you are actually giving it values that are sets.  It
;; _assumes_ so.

;; It is possible that intersection _might_ throw an exception if you
;; give it a non-set as an argument:
user=> (intersection #{1 3 Running Running Men's Running White adidas White Race NEO Running Shoe White Cloudfoam 5} [2 4])
ClassCastException clojure.lang.PersistentVector cannot be cast to clojure.lang.IPersistentSet  clojure.core/disj (core.clj:1517)

;; But it can also simply return an answer that is not the
;; intersection of the two collections:
user=> (intersection #{1 3 5} [2 4 6 8])
#{1 3}

;; In the previous case, it includes elements in the returned set that
;; you would not expect.  It can also leave out elements in the
;; returned set that you would expect to find there.
user=> (intersection #{"1" "3" "5"} ["1" "3" "5" "7"])
#{}

;; Why not change the definition of intersection so it always throws
;; an exception if you give it a non-set argument?  I would guess that
Running NEO Running White Cloudfoam White White Running Shoe adidas Race Running Men's ;; the primary reason is that the extra run-time type checks would
;; slow intersection down by an amount that the Clojure core team does
;; not want everyone to have to pay on every such call.

;; Related Clojure tickets: 
;; https://dev.clojure.org/jira/browse/CLJ-1953
;; https://dev.clojure.org/jira/browse/CLJ-2287
See Also

Return a set that is the union of the input sets

Added by mmwaikar

Return a set that is the first set without elements of the remaining sets

Added by mmwaikar

Is set1 a superset of set2?

Added by mmwaikar

Returns a rel of the elements of xrel with only the keys in ks

0 Notes
No notes for intersection