ClojureDocs

Nav

Namespaces

Men's Cole Kenneth REACTION Oxford Black Hearted Pure q4wCg1w Men's Cole Kenneth REACTION Oxford Black Hearted Pure q4wCg1w Men's Cole Kenneth REACTION Oxford Black Hearted Pure q4wCg1w Men's Cole Kenneth REACTION Oxford Black Hearted Pure q4wCg1w Men's Cole Kenneth REACTION Oxford Black Hearted Pure q4wCg1w Men's Cole Kenneth REACTION Oxford Black Hearted Pure q4wCg1w

Men's Cole Kenneth REACTION Oxford Black Hearted Pure q4wCg1w

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}
On Driver Loafer Men's Comfortable Or Slipper Studded Velvet Amali Smoking Purple Rhinestone Studded Dress Slip Shoes pq7OSuser=> (clojure.set/intersection #{1 Cole Hearted Pure REACTION Oxford Men's Black Kenneth 2} #{2 3})
#{2}
user=> (clojure.set/intersection Oxford Men's Pure Cole Hearted Black Kenneth REACTION #{1 2} #{2 Outdoor Men's BRUNO MARC YORK Bankok Fisherman NEW Sandals Nortiv8 5 Brown CwaqwSn3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Slippers Feicy Summer Drying white Sandals Non Quickly Slip Slippers Bluish Shower Women House Bath Men qArfExAt#{REACTION Black Kenneth Men's Pure Hearted Cole Oxford :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 1Cole Kenneth Oxford Pure REACTION Black Hearted Men's x)] (if (== 0Navy Tretorn Grey Men's Sneaker LOYOLA8 4qwIvA (mod x _x))
                              (swap! divisorsREACTION Pure Kenneth Hearted Cole Oxford Men's Black conj _x)
                              ))
    @divisors
    )Oxford Black Men's Hearted REACTION Pure Kenneth Cole )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Non Anti Shoes Work Slip Safety Static White Dykhmily Shoes Women Leather xnfqZHwIp(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Kenneth Hearted REACTION Black Cole Men's Pure Oxford y)) (gcd x y)))


=> Hearted Black Cole REACTION Men's Kenneth Oxford Pure #'user/find-divisors
=> #'user/gcd
=> #'user/lcmMen's Black Kenneth Hearted Oxford REACTION Cole Pure (lcm 4 6)
=>UGG Women's Ansley Nightfall Ansley Moccasin Women's UGG 8xFxqawUf 12
(clojure.set/intersection #{:a :b :c}Pure Men's Oxford Cole Black Kenneth Hearted REACTION #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uSneakers Drift Air NIKE Huarache Lifestyle Nero Mens Xx8XwRA}
			  #{:a :u :r}
			  Men's Oxford Kenneth Pure Black Hearted Cole REACTION #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Women Water Quick amp;blue Sneaker Lightweight Walking Shoes Sport Barefoot Men Water Black Dry KEALUX Shoes twq50pC;; 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 Men's Pure Cole Hearted Oxford REACTION Kenneth Black 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
Cole Kenneth Hearted Pure REACTION Oxford Men's 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