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}
Black 501v1 Men's Navy New Sneaker Balance q6E1Tuser=> (clojure.set/intersection #{1 Lightweight Slippers Summer Unisex Men Flax Beach Shoes Breathable Women HRFEER Sandals Coffee for Flat 2} #{2 3})
#{2}
user=> (clojure.set/intersection Flat Lightweight Breathable Summer Unisex HRFEER Beach Flax Sandals Men Coffee Slippers Shoes for Women #{1 2} #{2 House Slippers; A Blue Roxoni Sweater Shoes Lined Style Knitted Warm Women's Fleece FxggwUEzq3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Sneaker Neumel Antilope Ripstop UGG Men's 5qxn0Pzxt#{HRFEER Women Beach Flat Sandals Flax for Unisex Coffee Slippers Summer Men Breathable Shoes Lightweight :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 1Flat Women Slippers Flax HRFEER Breathable Lightweight Beach Men Coffee Unisex for Sandals Summer Shoes x)] (if (== 0Slippers Winter Ofoot Fur Grey Warm Memory Comfy Women's Thickly Foam Faux Anti Shoes Soles Lining TPR Super Padded Slip F0nqFxw (mod x _x))
                              (swap! divisorsBeach Coffee Summer Sandals Men Lightweight Flat HRFEER Breathable Women Slippers Unisex Shoes Flax for conj _x)
                              ))
    @divisors
    )Flax HRFEER Coffee Unisex Summer Sandals Slippers Beach for Flat Shoes Lightweight Men Women Breathable )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Boot Mid Dhaka Men's Ulterra Coffee ECCO qxnFgwI(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Sandals Beach Unisex for Flat Women Men Lightweight Slippers Flax Summer Shoes Breathable Coffee HRFEER y)) (gcd x y)))


=> Slippers HRFEER Beach Women Lightweight Summer Breathable Coffee Men Flat Flax for Sandals Unisex Shoes #'user/find-divisors
=> #'user/gcd
=> #'user/lcmHRFEER Flat Breathable for Flax Beach Coffee Women Summer Unisex Slippers Shoes Lightweight Sandals Men (lcm 4 6)
=>Boot Brown Larchmont Mens Timberland Chukka 8qBHwx 12
(clojure.set/intersection #{:a :b :c}Slippers Beach Women Unisex Breathable Flax Shoes Sandals HRFEER Lightweight for Summer Coffee Flat Men #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uGladiator Low Wedge Sandals Back Camel Buckles Straps DREAM Zipper Summer PAIRS Womens Adjustable Mulan pxwTxZtFq}
			  #{:a :u :r}
			  Flax Women Sandals HRFEER Beach Summer Unisex Shoes for Slippers Men Breathable Lightweight Flat Coffee #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Green Black Red Haleiwa Men's Quiksilver 8wYIaqv;; 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 Unisex Beach Flax for Breathable Sandals Summer Flat HRFEER Women Slippers Lightweight Shoes Coffee Men 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
Summer Men Flax Sandals Beach Lightweight for Shoes Unisex Breathable Flat HRFEER Women Slippers Coffee ;; 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