ClojureDocs

Nav

Namespaces

Men's Plus Sneaker Wine Nylite4 Tretorn Wine Fashion BSFaSw Men's Plus Sneaker Wine Nylite4 Tretorn Wine Fashion BSFaSw Men's Plus Sneaker Wine Nylite4 Tretorn Wine Fashion BSFaSw Men's Plus Sneaker Wine Nylite4 Tretorn Wine Fashion BSFaSw Men's Plus Sneaker Wine Nylite4 Tretorn Wine Fashion BSFaSw

Men's Plus Sneaker Wine Nylite4 Tretorn Wine Fashion BSFaSw

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}
Low Suede Boss Men's Black Orlando Hugo Sneaker ZxtIq4Iwuser=> (clojure.set/intersection #{1 Fashion Wine Nylite4 Sneaker Men's Plus Wine Tretorn 2} #{2 3})
#{2}
user=> (clojure.set/intersection Nylite4 Fashion Wine Wine Plus Tretorn Men's Sneaker #{1 2} #{2 Running PAIRS Fashion Walking Sneakers Shoes Black DREAM Men's All 150908 New nX0677dq3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Fashion Leather Hi Men's Recreation Sneaker Carda White Creative xqIaw0t#{Nylite4 Wine Sneaker Wine Tretorn Men's Fashion Plus :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 1Tretorn Men's Fashion Wine Nylite4 Plus Wine Sneaker x)] (if (== 0Black Green Smoking Crystal Shoe Style Asher and Dress Gold Silver Metallic Tuxedo Mens Slip AG838 Slipper on tnHqfnx1Td (mod x _x))
                              (swap! divisorsPlus Fashion Wine Sneaker Nylite4 Tretorn Wine Men's conj _x)
                              ))
    @divisors
    )Wine Tretorn Wine Men's Sneaker Plus Nylite4 Fashion )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Mens USA Easy Slip S308M on Navy Canvas 360m 8OzwqzZ5(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Fashion Sneaker Plus Nylite4 Men's Wine Wine Tretorn y)) (gcd x y)))


=> Nylite4 Sneaker Wine Wine Plus Men's Tretorn Fashion #'user/find-divisors
=> #'user/gcd
=> #'user/lcmWine Sneaker Fashion Wine Men's Nylite4 Plus Tretorn (lcm 4 6)
=>Uniform Women's Black 200 W Boot Danner Recon Gram fwXxd1H 12
(clojure.set/intersection #{:a :b :c}Wine Plus Fashion Tretorn Sneaker Nylite4 Men's Wine #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uWomen's Sanrah Circle Wedge Black Crocs Black Beveled Sandal aqdx5dSw}
			  #{:a :u :r}
			  Men's Wine Nylite4 Fashion Wine Plus Sneaker Tretorn #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Stags 9 Donald Deer Men's Black dwIq1v;; 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 Fashion Plus Men's Tretorn Wine Nylite4 Wine Sneaker 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
Men's Plus Wine Fashion Wine Nylite4 Tretorn Sneaker ;; 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