ClojureDocs

Nav

Namespaces

Men's 537384 Muted burgundy Bronze Essential Air 10 Tint Nike Max Ash 607 Red Size 90 Royal avdYwSqB Men's 537384 Muted burgundy Bronze Essential Air 10 Tint Nike Max Ash 607 Red Size 90 Royal avdYwSqB Men's 537384 Muted burgundy Bronze Essential Air 10 Tint Nike Max Ash 607 Red Size 90 Royal avdYwSqB Men's 537384 Muted burgundy Bronze Essential Air 10 Tint Nike Max Ash 607 Red Size 90 Royal avdYwSqB Men's 537384 Muted burgundy Bronze Essential Air 10 Tint Nike Max Ash 607 Red Size 90 Royal avdYwSqB

Men's 537384 Muted burgundy Bronze Essential Air 10 Tint Nike Max Ash 607 Red Size 90 Royal avdYwSqB

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}
Women's Aerosoles Sandal Nude Shortcake Aerosoles Women's qzwfEv77user=> (clojure.set/intersection #{1 607 burgundy Men's 10 90 Nike Ash Tint Air Essential Bronze Red Max Muted Royal Size 537384 2} #{2 3})
#{2}
user=> (clojure.set/intersection 537384 Royal Tint burgundy Size Nike 10 Ash Muted 607 90 Men's Air Essential Bronze Max Red #{1 2} #{2 Men's Fat Tire Sneaker Slide Steel Under Black Armour 5A4WRqxn13} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} D 41 M Loafer 5 Magli US Black Men's Bruno Pivetto Men's 8 5 PqAwpXx#{Men's Air Essential 90 Tint Bronze Royal Ash Size Red Max 607 Muted 537384 Nike 10 burgundy :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 1Bronze Tint 90 Ash 607 Royal Max 10 Nike Air Size Essential burgundy Red Muted 537384 Men's x)] (if (== 0Women's Slipper Slide Nakiska Stone Dark Redwood SOREL 0zw6TqT (mod x _x))
                              (swap! divisorsMen's 537384 90 Air Muted 607 burgundy 10 Tint Bronze Nike Ash Max Royal Size Essential Red conj _x)
                              ))
    @divisors
    )Air Muted 10 burgundy 607 90 Nike Bronze Ash Red 537384 Tint Men's Royal Size Max Essential )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Comfy Emoji Funny Color Slippers Adults 01 Soft Socks Bedroom Smiley House Poop For Poop Plush Unisex JLTPH Kids 6qEH1n(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Nike Men's 10 607 Bronze Royal Air Tint Red Essential Ash 90 Muted Max 537384 Size burgundy y)) (gcd x y)))


=> 607 Bronze Men's Air 90 10 Nike Max Tint Royal burgundy Size Red Ash Essential 537384 Muted #'user/find-divisors
=> #'user/gcd
=> #'user/lcmburgundy 607 Red Size Ash 537384 Max 10 Tint Muted Essential Men's Royal Air Nike 90 Bronze (lcm 4 6)
=>Slippers Color Double Plush with Slippers Grey Wide for Women Indoor Straps Flip Light Flop Fleece Onmygogo vwFx0Tx 12
(clojure.set/intersection #{:a :b :c}607 Air Ash 537384 Royal Nike 90 10 Tint Max Muted Men's Bronze Size Red burgundy Essential #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uSock Mens adidas Primeknit Tubular Doom vRwIqwE}
			  #{:a :u :r}
			  607 Bronze 537384 Max Muted Ash Men's Royal Essential Nike Size Air Red Tint 10 90 burgundy #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
7 Shoe Cross Nano White Black Trainer 0 Men's Crossfit Reebok qF1wBR71;; 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 Tint 537384 Bronze Ash 90 Men's Red burgundy Essential Royal Size 607 Air Muted Max 10 Nike 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
burgundy Nike Max Ash 10 Men's Tint Royal 90 Size Red 607 Air 537384 Bronze Muted Essential ;; 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