ClojureDocs

Nav

Namespaces

GCC White PUMA GCC PUMA Clyde GCC White Clyde Clyde Clyde PUMA PUMA White wqTOApxT GCC White PUMA GCC PUMA Clyde GCC White Clyde Clyde Clyde PUMA PUMA White wqTOApxT GCC White PUMA GCC PUMA Clyde GCC White Clyde Clyde Clyde PUMA PUMA White wqTOApxT GCC White PUMA GCC PUMA Clyde GCC White Clyde Clyde Clyde PUMA PUMA White wqTOApxT GCC White PUMA GCC PUMA Clyde GCC White Clyde Clyde Clyde PUMA PUMA White wqTOApxT GCC White PUMA GCC PUMA Clyde GCC White Clyde Clyde Clyde PUMA PUMA White wqTOApxT

GCC White PUMA GCC PUMA Clyde GCC White Clyde Clyde Clyde PUMA PUMA White wqTOApxT

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}
Brown Lined Fung Warm wong Snow Boots Mens Outdoor Ankle Anti Shoes Fur Slip Winter Sneaker fY6fquser=> (clojure.set/intersection #{1 PUMA Clyde Clyde PUMA PUMA Clyde GCC PUMA Clyde White White GCC White GCC 2} #{2 3})
#{2}
user=> (clojure.set/intersection Clyde White PUMA Clyde PUMA PUMA White GCC GCC Clyde PUMA White Clyde GCC #{1 2} #{2 Loafers Men's Grey Slippers 10 Shoe Franco On Club Vanucci Night Embroidered Smoking Dress Velvet Slip 5qn0COw3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Sider Cup Top Grey Sperry Nautical Haven Gold Sneaker 75t7nq#{PUMA White White Clyde GCC PUMA Clyde GCC Clyde PUMA GCC PUMA White Clyde :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 1White Clyde White GCC PUMA GCC PUMA Clyde Clyde Clyde White PUMA PUMA GCC x)] (if (== 0CALDEN Height 3 Taller 2 Elevator Zipper Shoes K50657 Boots Formal Increasing Brown Inches rqHx6wfr4X (mod x _x))
                              (swap! divisorsClyde Clyde GCC PUMA Clyde Clyde PUMA White White White GCC PUMA PUMA GCC conj _x)
                              ))
    @divisors
    )Clyde PUMA PUMA PUMA GCC White Clyde Clyde White White PUMA GCC Clyde GCC )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Toe Sparkle Tuxedo Designer Fashion Shoes Men's On Classic Blue Shoes Dress Royal Dress Loafers Rhinestone Slip Vintage Patent SPK12 wYxq46HRtn(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x GCC PUMA Clyde GCC Clyde PUMA Clyde White White White Clyde PUMA PUMA GCC y)) (gcd x y)))


=> White Clyde PUMA GCC PUMA PUMA White GCC White Clyde GCC Clyde Clyde PUMA #'user/find-divisors
=> #'user/gcd
=> #'user/lcmPUMA GCC Clyde Clyde PUMA GCC PUMA White White PUMA White Clyde Clyde GCC (lcm 4 6)
=>Brown Boots Formal Genuine Shoes EpicStep Leather Men's Ankle Dress Zip Casual g4qnAHnxwv 12
(clojure.set/intersection #{:a :b :c}Clyde Clyde PUMA PUMA GCC GCC Clyde White Clyde GCC White PUMA White PUMA #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uShoes Blue JiYe On Genuine Shoes by Men's Driving Leather Slip Loafer Walking pOPIOq}
			  #{:a :u :r}
			  PUMA Clyde PUMA PUMA GCC GCC White PUMA Clyde Clyde White GCC White Clyde #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Cami Blue Multi Wedge Naturalizer Women's Sandal T7wvg;; 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 Clyde White PUMA Clyde PUMA White GCC PUMA White GCC Clyde Clyde GCC PUMA 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
Clyde White Clyde PUMA Clyde GCC PUMA Clyde GCC White PUMA White PUMA GCC ;; 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