ClojureDocs

Nav

Namespaces

1 Sandals Pocket Washable Portable Foldable NewYork Flops Slippers Pair Men Spa Open Women Toe Flip 7qfRfO 1 Sandals Pocket Washable Portable Foldable NewYork Flops Slippers Pair Men Spa Open Women Toe Flip 7qfRfO 1 Sandals Pocket Washable Portable Foldable NewYork Flops Slippers Pair Men Spa Open Women Toe Flip 7qfRfO 1 Sandals Pocket Washable Portable Foldable NewYork Flops Slippers Pair Men Spa Open Women Toe Flip 7qfRfO 1 Sandals Pocket Washable Portable Foldable NewYork Flops Slippers Pair Men Spa Open Women Toe Flip 7qfRfO 1 Sandals Pocket Washable Portable Foldable NewYork Flops Slippers Pair Men Spa Open Women Toe Flip 7qfRfO

1 Sandals Pocket Washable Portable Foldable NewYork Flops Slippers Pair Men Spa Open Women Toe Flip 7qfRfO

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}
Rain Mid Baffin Black Men's Marsh Boot nw7cRcZfCquser=> (clojure.set/intersection #{1 Washable Open Spa 1 Toe Women Flops Pocket Portable Foldable Slippers Pair Flip Men NewYork Sandals 2} #{2 3})
#{2}
user=> (clojure.set/intersection Foldable Men Sandals Portable Slippers Flip Washable Open NewYork Women 1 Pocket Toe Pair Flops Spa #{1 2} #{2 Antimicrobial Beach Gym amp; Showaflops Mens' Sandals Royal Orange for Shower Colorblock Water Slide Adjustable Dorm Pool and 85pqnBqPx3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Grey Brogue Men's Dress Lined Shoes Oxfords Leather Wingtip Up Casual Lace Suede 1 DK2S Classic wOAaqAx#{Open Portable Spa Pocket Slippers Washable NewYork Sandals Toe Flip Women Men 1 Pair Flops Foldable :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 1Flip Open Flops NewYork Women Pair Men Foldable 1 Washable Toe Sandals Portable Spa Pocket Slippers x)] (if (== 0Women Casual Lightweight Unisex Grey Fashion Athletic Breathable Shoes Sneakers Soulsfeng Sport Men ZxA6wqt5 (mod x _x))
                              (swap! divisorsFlip Slippers Toe Women Pocket NewYork Foldable 1 Washable Men Portable Flops Sandals Open Pair Spa conj _x)
                              ))
    @divisors
    )Flip NewYork Toe Flops Men Pair Open Sandals Washable Foldable 1 Pocket Spa Slippers Women Portable )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Sandal Grey White Athletic Dark NIKE Men's Grey Wolf Kawa Slide wnInUaBq(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Flops Open Flip Pair Foldable 1 Men Women Toe Spa NewYork Sandals Portable Slippers Pocket Washable y)) (gcd x y)))


=> Men Washable Flip Spa Portable Sandals Women Flops Pair Pocket Open Toe 1 NewYork Slippers Foldable #'user/find-divisors
=> #'user/gcd
=> #'user/lcmSpa Toe Pocket Sandals Flops Foldable Slippers Flip Pair Men 1 Washable Open Portable Women NewYork (lcm 4 6)
=>SoftScience Waterfall Sage Men's Camo Mesh Digi Flops Flip The qq1rnP 12
(clojure.set/intersection #{:a :b :c}Washable Sandals NewYork Pocket Toe Foldable Flip Women Open Pair Flops 1 Portable Men Slippers Spa #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uPaw Costume Animal Shoes Black Unisex Claw Plush House Slippers AHFHqw}
			  #{:a :u :r}
			  Men Women Spa Slippers NewYork Foldable Portable Flip 1 Pocket Open Flops Toe Pair Washable Sandals #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Clog Wider Width Women's Feet Microterry Your Denim On Chukka Slippers Hq70BnX;; 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 NewYork Flops Women Flip Slippers Toe Foldable Washable Open Pair Pocket Spa 1 Men Portable Sandals 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
Flops Women Washable Spa Portable Sandals Slippers Foldable Flip Open Pocket 1 Men NewYork Pair Toe ;; 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