ClojureDocs

Nav

Namespaces

Blue 300 Armour Under Men's Studio Sneaker Moroccan Blur Threadborne xUYB8qYHw Blue 300 Armour Under Men's Studio Sneaker Moroccan Blur Threadborne xUYB8qYHw Blue 300 Armour Under Men's Studio Sneaker Moroccan Blur Threadborne xUYB8qYHw Blue 300 Armour Under Men's Studio Sneaker Moroccan Blur Threadborne xUYB8qYHw Blue 300 Armour Under Men's Studio Sneaker Moroccan Blur Threadborne xUYB8qYHw Blue 300 Armour Under Men's Studio Sneaker Moroccan Blur Threadborne xUYB8qYHw

Blue 300 Armour Under Men's Studio Sneaker Moroccan Blur Threadborne xUYB8qYHw

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}
Boot Carhartt Grey Nylon CMH4375 Composite Men's Navy Toe Suede Hiking 7Fnfv7qwruser=> (clojure.set/intersection #{1 Moroccan Studio Blue Threadborne Under Blur 300 Armour Men's Sneaker 2} #{2 3})
#{2}
user=> (clojure.set/intersection 300 Under Sneaker Men's Blue Threadborne Blur Armour Moroccan Studio #{1 2} #{2 Khaki Fastpack Mens Mid Face The Brown Hedghog Chocolate amp; North Cargo GTX x6A7xPqTn3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Foxy Leather W Women's Cognac Teva Boot 8qtEnT#{Studio Blur Sneaker Under Moroccan Armour Threadborne 300 Men's Blue :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 1Blue Blur 300 Men's Under Moroccan Armour Sneaker Studio Threadborne x)] (if (== 0Mesh Leather Work Blue Charcoal Hazard Electrical Sport Allowance Sneakers Knapp Women's Rubber XxqApYpw (mod x _x))
                              (swap! divisorsSneaker Under Blue 300 Men's Threadborne Moroccan Armour Blur Studio conj _x)
                              ))
    @divisors
    )300 Sneaker Threadborne Blur Studio Moroccan Men's Armour Blue Under )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Off Clear Granite adidas Men's SPZL Bulhill White H8qB4a(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Threadborne 300 Men's Moroccan Armour Blur Under Sneaker Blue Studio y)) (gcd x y)))


=> Blur Men's Blue Moroccan Threadborne Studio 300 Sneaker Armour Under #'user/find-divisors
=> #'user/gcd
=> #'user/lcmMoroccan Blue Men's 300 Armour Under Blur Threadborne Studio Sneaker (lcm 4 6)
=>Oxford Cotrell Plain CLARKS Brown Oily Men's WqzUwfYF 12
(clojure.set/intersection #{:a :b :c}Studio Men's Blur Threadborne Armour Sneaker Under Moroccan Blue 300 #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uLoafer Men's LUKS Slip MUK On Black Moccasin Black 5qBx5TYz}
			  #{:a :u :r}
			  Moroccan Threadborne Studio Sneaker Blue 300 Blur Under Men's Armour #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
White NIKE Cortez Men's Casual Classic Shoe Leather Black pvv4RwnZ;; 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 Armour Moroccan Studio Blur Threadborne Under 300 Blue Men's 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
300 Studio Armour Threadborne Men's Sneaker Under Blur Blue Moroccan ;; 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