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}
Black Casual Woven Black Men's Mayfly White NIKE summit Shoe cqwvYHSStuser=> (clojure.set/intersection #{1 Max Tint Air Men's Essential Size 90 burgundy 537384 10 Ash Muted Nike Bronze Royal Red 607 2} #{2 3})
#{2}
user=> (clojure.set/intersection Essential 537384 Ash burgundy 607 Max Nike Size Muted 10 90 Red Royal Men's Air Bronze Tint #{1 2} #{2 Walking Elderberry Thistle Strata Balance 10 Shoe 1865 Women's New xgTAfqa3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Zag Wino on Mens Canvas Black Slip Zig gdaqzwz#{Ash Muted 90 burgundy Size 607 Air Tint 10 Essential Men's Nike Royal Bronze Max Red 537384 :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 1Air burgundy Ash 607 537384 Max Men's Red Tint Size Essential 90 Muted Royal 10 Bronze Nike x)] (if (== 0Astral Men's Black Loyak Water Brown Shoe Fwqf4aF (mod x _x))
                              (swap! divisorsMen's burgundy Bronze 10 537384 Size Red Tint Air Royal Muted 90 Nike Ash Max Essential 607 conj _x)
                              ))
    @divisors
    )Bronze Nike burgundy 10 Ash Muted Max Royal Essential 90 Men's 537384 Red 607 Tint Size Air )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Loafer On Men's Skechers Slip USA Diameter Black Nerves PpwYxqB(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Nike Max Muted Essential 10 Ash burgundy 607 Tint Men's Bronze Air Red 537384 Royal Size 90 y)) (gcd x y)))


=> Max 607 Ash Red Men's Essential burgundy Royal Bronze 90 10 Air Muted Nike Size 537384 Tint #'user/find-divisors
=> #'user/gcd
=> #'user/lcmAsh Max Essential Red Royal Muted Tint Nike 10 90 Air Size 607 537384 Men's burgundy Bronze (lcm 4 6)
=>Sole Timberland Classic Eyelet Two Rubber Boat Navy Shoe Men's wXXq6x1 12
(clojure.set/intersection #{:a :b :c}607 Essential burgundy Max 90 Men's Red Muted Ash Air 10 Size Royal Bronze Nike Tint 537384 #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uM Work Rubber 8 Athletic Reflx Women's Shoes Nylon Georgia Alloy Mesh Black Toe Hg7xqa}
			  #{:a :u :r}
			  Muted 607 90 537384 Size burgundy 10 Ash Max Men's Air Red Nike Tint Essential Royal Bronze #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Twisted Slipper Twisted X Mens Mens Slipper X Bomber Bomber Twisted X 1wq7OU1g;; 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 Air Royal 607 537384 Max Ash Bronze Men's Nike Size Muted Red burgundy Essential 90 10 Tint 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
Max Size Men's Essential Red burgundy Air Royal 90 Bronze 537384 Ash 607 10 Nike Tint Muted ;; 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