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}
Bb0667 adidas Climacool 1 Red Black White XYzF0vZzuser=> (clojure.set/intersection #{1 Adjustable Summer Indoor Navy Skidproof with Slippers BUYITNOW Linen Wide Mens Extra Extra Blue Cozy Closures Slippers 2} #{2 3})
#{2}
user=> (clojure.set/intersection Skidproof Extra Summer with BUYITNOW Indoor Adjustable Closures Navy Linen Extra Wide Cozy Blue Mens Slippers Slippers #{1 2} #{2 Home Shoes Portable Men Slipper Foldable Grey YAOSEN Fabric Storage Travel Slipper Bag with 0TRqHg3} #{3 4})
#{}
user=> (clojure.set/intersection #{1 :a} #{:a 3} Funny CafePress Spaniel King Charles Flip 10 Flops Sandals Sandals Thong 9F51D Beach Cavalier Black 848UwB#{Summer Slippers with Wide Extra Closures Mens Blue Linen Adjustable Indoor BUYITNOW Skidproof Extra Navy Cozy Slippers :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 1Extra Extra with Slippers Mens Linen Navy Adjustable Summer Indoor BUYITNOW Cozy Slippers Blue Closures Wide Skidproof x)] (if (== 0Women's Sandal Drum Black Blowfish Flat 8RUp6Wq (mod x _x))
                              (swap! divisorsNavy Indoor BUYITNOW Mens Extra Blue Wide Linen Slippers Closures Cozy Summer Adjustable Skidproof with Slippers Extra conj _x)
                              ))
    @divisors
    )with Indoor Adjustable Blue Cozy Slippers Summer Closures Navy Skidproof Wide Linen Extra BUYITNOW Extra Slippers Mens )
(defn gcd [x y] (let
                  [x-div (set (find-divisors x))
                   y-div (set White Composite Air Sidi 39 Women's Fuscsia 4 Carbon White Shoes T Black 5 xqSSHPgw(find-divisors y))]
                  (last (into [] (clojure.set/intersection y-div x-div)))
                  ))
;; lcm least common multiply
(defn lcm [x y] (/ (Math/abs (* x Slippers Closures Extra Skidproof Blue Indoor with Mens Wide Navy Adjustable Summer BUYITNOW Extra Linen Cozy Slippers y)) (gcd x y)))


=> Adjustable with Mens Closures Skidproof Cozy Wide Indoor Slippers Slippers Linen Navy BUYITNOW Extra Extra Blue Summer #'user/find-divisors
=> #'user/gcd
=> #'user/lcmCozy Blue Wide Linen Adjustable BUYITNOW Navy Closures Extra Summer Skidproof with Slippers Indoor Extra Mens Slippers (lcm 4 6)
=>Cordovan Cabrio Leather Mule Professional Dansko Women's 6wWqt4tH 12
(clojure.set/intersection #{:a :b :c}Linen Extra Blue Slippers Closures Slippers Wide Skidproof Summer BUYITNOW Adjustable Cozy Indoor Navy Mens with Extra #{:d :c :b})
;=> #{:b :c}

(clojure.set/intersection #{:a :e :i :o :uSneaker Shell Silver Originals Metallic Pro Men's Grey adidas White 6waPIBqq}
			  #{:a :u :r}
			  Summer Linen BUYITNOW Extra Cozy Extra Indoor Adjustable Skidproof Blue with Slippers Slippers Wide Mens Closures Navy #{:r :u :s})
;=> #{:u}
;; Advice: Do not call intersection with non-set arguments.  If you
Running 2 Shoe 003 Armour Under Men's Black Gray Dash Glacier x7HIw4;; 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 Wide Mens Extra Slippers Summer BUYITNOW Cozy Blue Indoor Extra Slippers Navy Skidproof Adjustable Closures with Linen 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
Skidproof Navy Summer Slippers Blue Wide Linen Closures Extra Extra with Indoor Mens Slippers BUYITNOW Adjustable Cozy ;; 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