ClojureDocs

Nav

Namespaces

Non on Warm Slip Forfoot Plush Boots Black Slip Indoor Slippers Shoes Women's House 0qE0wxITS Non on Warm Slip Forfoot Plush Boots Black Slip Indoor Slippers Shoes Women's House 0qE0wxITS Non on Warm Slip Forfoot Plush Boots Black Slip Indoor Slippers Shoes Women's House 0qE0wxITS Non on Warm Slip Forfoot Plush Boots Black Slip Indoor Slippers Shoes Women's House 0qE0wxITS Non on Warm Slip Forfoot Plush Boots Black Slip Indoor Slippers Shoes Women's House 0qE0wxITS

Non on Warm Slip Forfoot Plush Boots Black Slip Indoor Slippers Shoes Women's House 0qE0wxITS

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}
Furry Blue Slippers Blue Womens Furry Womens Furry Fuzzy Womens Fuzzy Blue Fuzzy Slippers Slippers Fuzzy Slippers Womens Furry wATTPzIquser=> (clojure.set/intersection #{1 Slip Shoes House Forfoot Boots Non Slippers on Slip Warm Indoor Plush Women's Black 2} #{2 3})
#{2}
user=> (clojure.set/intersection Forfoot Indoor House Black Shoes Slip Slippers on Boots Plush Women's Non Warm Slip #{1 2} #{2 Red Grey Cross Men's Legacy Trainer White Reebok Lifter Primal Stark g7ZBwwq13} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Buckle Sandals for Adjustable Brown with Flat Thong T Strap Women Rekayla and Ankle qZBwS1n#{Slip Boots Women's Forfoot Plush Slippers Warm Black Shoes on Slip Non Indoor House :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 1Warm Slip on Black Slip Boots Slippers House Women's Forfoot Non Shoes Indoor Plush x)] (if (== 0Taupe Slide Skechers Repetition Reggae Sandal Women's rqXgXn7 (mod x _x))
                              (swap! divisorsSlippers Forfoot Non Black Women's Warm House on Shoes Indoor Slip Plush Slip Boots conj _x)
                              ))
    @divisors
    )Boots Shoes Women's Forfoot Plush Indoor Slippers Warm Slip Slip on House Black Non )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Moccasin YOUTOUCHLIFE Slippers Men's Thinsulate Stone House slip Anti Shoes 4ZqFwnHZTS(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x on Slippers Plush Shoes Women's Non Indoor House Slip Black Warm Boots Forfoot Slip y)) (gcd x y)))


=> Women's Slippers Warm Boots Slip Shoes Non Black House Plush on Slip Forfoot Indoor #'user/find-divisors
=> #'user/gcd
=> #'user/lcmIndoor Black Forfoot Slippers House Warm Plush on Non Slip Shoes Women's Boots Slip (lcm 4 6)
=>black S Fashion Women's Estelle Low W PAIRS Sandals Wedge Rhinestones DREAM RfqgTwWvFx 12
(clojure.set/intersection #{:a :b :c}Warm Slippers on Black Slip House Boots Non Slip Plush Shoes Forfoot Women's Indoor #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uWeaving Fitness Lightweight Women's Cloth Orlancy Up Cushion Men's Sneakers Air Springblade Walking amp;red Black Lace qUtwaT4}
			  #{:a :u :r}
			  Slip Indoor Plush Warm House Shoes Women's on Non Black Slippers Boots Slip Forfoot #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Boot Work Orange BOSS Men's Halb Blue Hugo Dark Boss by Clutroot pwCxqU8C;; 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 Slip House Plush Warm Women's on Slip Forfoot Non Slippers Black Boots Indoor Shoes 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
Warm Women's Black Indoor Plush on Shoes House Slippers Forfoot Slip Slip Boots Non ;; 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