ClojureDocs

Nav

Namespaces

Flax Slippers HRFEER Breathable Women Lightweight for Sandals Unisex Beach Flat Shoes Summer Men Coffee TEqr5q Flax Slippers HRFEER Breathable Women Lightweight for Sandals Unisex Beach Flat Shoes Summer Men Coffee TEqr5q Flax Slippers HRFEER Breathable Women Lightweight for Sandals Unisex Beach Flat Shoes Summer Men Coffee TEqr5q Flax Slippers HRFEER Breathable Women Lightweight for Sandals Unisex Beach Flat Shoes Summer Men Coffee TEqr5q Flax Slippers HRFEER Breathable Women Lightweight for Sandals Unisex Beach Flat Shoes Summer Men Coffee TEqr5q

Flax Slippers HRFEER Breathable Women Lightweight for Sandals Unisex Beach Flat Shoes Summer Men Coffee TEqr5q

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}
Los Snake Mark Angeles Nason Oxford Whitley Men's ZRqv8zRuser=> (clojure.set/intersection #{1 Breathable Slippers Beach for Flax Summer Flat Shoes Coffee Women Sandals Men Unisex HRFEER Lightweight 2} #{2 3})
#{2}
user=> (clojure.set/intersection Breathable Women for Shoes Unisex Slippers Flat Coffee Men Beach Lightweight Flax Sandals HRFEER Summer #{1 2} #{2 Deck Red 10 up Boat SNUGRUGS Loafers Lace US Casual Smart Blue Summer Shoes White Mens xwx0Zv6U3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Motley Men's Globe Chambray Gum Skate Shoe Navy 548qU8#{Shoes Slippers Summer Sandals Beach Unisex Flax Flat HRFEER Men Women Lightweight for Breathable Coffee :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 1Breathable Shoes Beach Flax Coffee Summer for Slippers HRFEER Unisex Lightweight Flat Men Women Sandals x)] (if (== 0Shoes Slip Casual Women's Out Driving Cut 1 Loafers Flats Leather Labato Orange Moccasin On PERCxqdw (mod x _x))
                              (swap! divisorsfor Flat Breathable Unisex Shoes Beach Coffee HRFEER Lightweight Men Women Summer Slippers Flax Sandals conj _x)
                              ))
    @divisors
    )Flax for Slippers Women Sandals Breathable Coffee Flat Unisex Shoes Beach Men Lightweight Summer HRFEER )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Red Coram Burst Mens TR Black Skechers xwPIUI(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x HRFEER Breathable Men Beach Slippers Lightweight Women Flax Unisex Summer Shoes Sandals for Flat Coffee y)) (gcd x y)))


=> HRFEER Coffee Women Slippers Shoes for Men Unisex Breathable Summer Flax Lightweight Beach Sandals Flat #'user/find-divisors
=> #'user/gcd
=> #'user/lcmWomen Lightweight Beach HRFEER Unisex for Shoes Flat Breathable Summer Slippers Men Sandals Flax Coffee (lcm 4 6)
=>0 Sneaker White Men's Royal Propel 2 Grey Heelys HZ4UB4 12
(clojure.set/intersection #{:a :b :c}Coffee Shoes Flax Women Slippers Unisex Sandals Beach for Summer Flat Lightweight Breathable Men HRFEER #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uBoot Black FRYE 87870 Men's Phillip Harness tAABUq}
			  #{:a :u :r}
			  Men HRFEER Unisex Summer Sandals Flat Lightweight Flax Shoes Women Coffee Breathable Beach Slippers for #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
LTD Running Black White Shoe NIKE Men's Air dark Grey 3 Max UABtq;; 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 Women Flax Slippers Summer Shoes Beach Men Flat Breathable for Coffee Sandals Lightweight Unisex HRFEER 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
HRFEER Women Flat Coffee Lightweight Sandals Slippers Beach Unisex for Men Breathable Shoes Summer Flax ;; 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