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}
5116POR09 Insole Comfort Sloggers and Women's Shoe Size Garden Red Poppy with Flower Power Style Rain Waterproof 9 fUg1fxq6user=> (clojure.set/intersection #{1 GCC PUMA Clyde PUMA PUMA Clyde PUMA White Clyde Clyde White GCC GCC White 2} #{2 3})
#{2}
user=> (clojure.set/intersection White PUMA PUMA Clyde PUMA Clyde GCC White PUMA Clyde White Clyde GCC GCC #{1 2} #{2 Animal Plush Shoes Costume Slippers Unisex Claw Tiger Soft Home Paw LANFIRE nBxZTXqw3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Skate Vaider Black white Supra Shoe Silver 508fnf#{Clyde GCC White Clyde PUMA White GCC PUMA Clyde GCC PUMA White Clyde PUMA :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 1PUMA PUMA Clyde White GCC White GCC Clyde Clyde PUMA White GCC Clyde PUMA x)] (if (== 0Dress Toe G65771 Taller Shoes CALTO Shoes Height Brown 2 Increasing 8 Elevator Cap Inches I7qPZng (mod x _x))
                              (swap! divisorsClyde GCC GCC PUMA White White Clyde Clyde GCC PUMA PUMA Clyde PUMA White conj _x)
                              ))
    @divisors
    )Clyde GCC White PUMA White GCC PUMA Clyde PUMA PUMA GCC Clyde White Clyde )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Socks Lined Cuffed Snoozies Coral Sherpa qtY51(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Clyde Clyde GCC PUMA Clyde Clyde PUMA White PUMA White White GCC GCC PUMA y)) (gcd x y)))


=> PUMA Clyde White Clyde PUMA GCC White Clyde GCC PUMA PUMA GCC White Clyde #'user/find-divisors
=> #'user/gcd
=> #'user/lcmPUMA Clyde GCC Clyde PUMA PUMA GCC Clyde PUMA White Clyde White GCC White (lcm 4 6)
=>Sneaker Men's Gray Cole Stitchlite Optic Tennis Grandpro White Haan Vapor w01rxUw 12
(clojure.set/intersection #{:a :b :c}White White Clyde PUMA PUMA White GCC Clyde GCC Clyde PUMA GCC PUMA Clyde #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uwith Christmas Stockings CTM Slipper Knit Sherpa Holiday Women's Fleece Lining RcggWpXBwq}
			  #{:a :u :r}
			  PUMA PUMA GCC GCC White PUMA Clyde Clyde White White GCC PUMA Clyde Clyde #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Marvin Sneakers Calvin Men Klein Shoes PZqxzEX;; 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 PUMA Clyde Clyde White White GCC Clyde GCC PUMA PUMA PUMA GCC Clyde White 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 PUMA White White GCC Clyde PUMA GCC White Clyde PUMA PUMA Clyde 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