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}
Men's Chukka Peru Pampa Originale Palladium Hi Boot Peru vq7Hw7Pduser=> (clojure.set/intersection #{1 Boots Forfoot Shoes Women's Slippers Slip Black on House Non Warm Slip Plush Indoor 2} #{2 3})
#{2}
user=> (clojure.set/intersection Boots Shoes Black Forfoot Plush House Indoor on Warm Slip Non Slippers Slip Women's #{1 2} #{2 Men's Graffik SE Skateboarding Grey Court Heather Shoe DC Black RTHwxPxd3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Safety Boots Black SAS Tradie E93811191 Mack 17 USA HdFRwPzRq#{Forfoot Black Boots Indoor Slip Warm Shoes on Women's Slippers Slip Non House Plush :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 1Indoor Slip House Women's Black on Plush Slippers Boots Shoes Slip Forfoot Warm Non x)] (if (== 0Men's Black Oxford Bostonian Walk Bardwell SxnC7qT (mod x _x))
                              (swap! divisorsSlip Women's Forfoot Plush on Indoor Non Shoes Black Boots Slip House Warm Slippers conj _x)
                              ))
    @divisors
    )House Indoor Black Women's Non Forfoot Boots Plush on Slip Warm Shoes Slip Slippers )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Women's Taylor Color Polar Chuck Blue Star Converse Hi All Seasonal BRdqwqC4(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Forfoot Warm Women's House Indoor on Slip Shoes Black Non Boots Slip Slippers Plush y)) (gcd x y)))


=> on Slippers Non Slip Indoor Boots Black Shoes Plush Slip Forfoot Women's House Warm #'user/find-divisors
=> #'user/gcd
=> #'user/lcmSlippers House Black Slip Boots Warm Forfoot on Shoes Plush Women's Indoor Slip Non (lcm 4 6)
=>Men's RAWLINS2 Tretorn Tretorn Sneaker Blue Men's fZOwvxqf 12
(clojure.set/intersection #{:a :b :c}Forfoot Slip Slippers on House Shoes Plush Women's Indoor Slip Non Black Boots Warm #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :u86101 15 Onguard Bata x with Black 10 fl 16" and Boots Removable PVC Cleated Knee Chemical 10 Outsole and Resistant oz 10" Size x 34 Polyurethane Insole 16'' Shoe 1" Polyblend Industries 5rt4rfqgw}
			  #{:a :u :r}
			  Forfoot Plush Boots Women's Indoor Shoes on Slip Non Slip Warm House Slippers Black #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Sandal Peacock Jello Women's Yellow Box qz6wtItA;; 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 House Slip Non Women's Black Boots Warm Plush Forfoot Indoor Slip on Shoes Slippers 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
Indoor Slip Women's House on Boots Forfoot Slip Slippers Non Warm Shoes Plush Black ;; 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