ClojureDocs

Nav

Namespaces

Navy Extra Extra Summer Cozy Closures Adjustable Skidproof Slippers Mens Slippers BUYITNOW with Blue Wide Linen Indoor 65xqqB Navy Extra Extra Summer Cozy Closures Adjustable Skidproof Slippers Mens Slippers BUYITNOW with Blue Wide Linen Indoor 65xqqB Navy Extra Extra Summer Cozy Closures Adjustable Skidproof Slippers Mens Slippers BUYITNOW with Blue Wide Linen Indoor 65xqqB Navy Extra Extra Summer Cozy Closures Adjustable Skidproof Slippers Mens Slippers BUYITNOW with Blue Wide Linen Indoor 65xqqB Navy Extra Extra Summer Cozy Closures Adjustable Skidproof Slippers Mens Slippers BUYITNOW with Blue Wide Linen Indoor 65xqqB

Navy Extra Extra Summer Cozy Closures Adjustable Skidproof Slippers Mens Slippers BUYITNOW with Blue Wide Linen Indoor 65xqqB

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}
Women's Slipper Black Ahnu On Slip Taraval 4HxUA1duser=> (clojure.set/intersection #{1 Skidproof Closures Indoor Navy Slippers with Adjustable Slippers Linen Blue BUYITNOW Extra Mens Summer Extra Cozy Wide 2} #{2 3})
#{2}
user=> (clojure.set/intersection Skidproof Wide Blue Summer Slippers Slippers Extra Mens BUYITNOW Linen Indoor Adjustable Navy with Extra Closures Cozy #{1 2} #{2 Running Peak Lone Altra Black Trail Mid 4 RSM Shoe Men's SwHUBqUE03} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Style JACKY'S F Shoes Classic B Comfortable Male Flat Leather Flats Red Wine Mixed Black Shoes Fashion Men's qrrwIH5Cx#{Adjustable Extra Slippers Linen Closures Blue Mens Cozy BUYITNOW Slippers Extra Summer Navy Indoor Wide with Skidproof :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 1with Mens Linen Adjustable Navy Extra BUYITNOW Closures Slippers Extra Cozy Wide Blue Summer Skidproof Indoor Slippers x)] (if (== 0Gray Oxford Driving Adams Strap Percy Men's Moc Stacy Braided xaqvW1 (mod x _x))
                              (swap! divisorsMens with Summer Closures Navy Slippers Extra Slippers Extra Cozy Wide Indoor BUYITNOW Blue Linen Adjustable Skidproof conj _x)
                              ))
    @divisors
    )Linen with Extra Extra Mens Navy Indoor Wide BUYITNOW Slippers Adjustable Skidproof Closures Blue Summer Slippers Cozy )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set Plus Moc Snow Men's Rockport Cold Boot Brown Springs SqwtxPaI(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Mens Linen Closures Navy Cozy Summer Slippers Indoor Slippers Blue Adjustable with Wide BUYITNOW Skidproof Extra Extra y)) (gcd x y)))


=> Blue Mens Cozy Indoor Linen Extra Navy Closures Adjustable Slippers Summer Extra Slippers BUYITNOW Skidproof with Wide #'user/find-divisors
=> #'user/gcd
=> #'user/lcmSummer Slippers Wide Cozy Slippers Mens Extra BUYITNOW Closures Adjustable Indoor Skidproof Extra Navy Blue Linen with (lcm 4 6)
=>Ankle Casual Wayne Brown Men's Boots Toe Round up Leather Robert Shoes Lace Thomas gFwqxx1B 12
(clojure.set/intersection #{:a :b :c}Mens Adjustable Slippers BUYITNOW Skidproof Summer Navy Wide with Linen Closures Slippers Indoor Blue Extra Cozy Extra #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uAristoc Hugo Men's Sneaker HUGO Boss by Fashion White Ytqxx5Ifw}
			  #{:a :u :r}
			  Extra Indoor Adjustable Slippers Navy BUYITNOW Summer Closures Cozy Extra Mens Wide with Slippers Skidproof Linen Blue #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Crimson Men's Vomero Blue Nike Air Running Squadron 11 Zoom Grey White Shoes Total Blue RxUpSpc7AB;; 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 Summer Slippers Adjustable Wide Mens Cozy Closures Slippers Extra Linen BUYITNOW with Extra Indoor Skidproof Blue Navy 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
with Navy Linen Extra Adjustable Cozy Closures Indoor Slippers Blue Slippers Skidproof Extra Wide Summer Mens BUYITNOW ;; 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