2014-01-26 00:04:22 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "You can create a set by converting another collection"
|
2016-02-27 20:53:16 +00:00
|
|
|
(= #{3} (set [3]))
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Counting them is like counting other collections"
|
2016-02-27 20:53:16 +00:00
|
|
|
(= 3 (count #{1 2 3}))
|
2010-09-30 23:34:02 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Remember that a set is a *mathematical* set"
|
2016-02-27 20:53:16 +00:00
|
|
|
(= #{1 2 3 4 5} (set '(1 1 2 2 3 3 4 4 5 5))) ;; J - This creates a unique ORDERED set so it's always sorted.
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "You can ask clojure for the union of two sets"
|
2016-02-27 20:53:16 +00:00
|
|
|
(= #{1 2 3 4 5} (set/union #{1 2 3 4} #{2 3 5})) ;; J - Uniting sets still orders them and keeps elements unique
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "And also the intersection"
|
2016-02-27 20:53:16 +00:00
|
|
|
(= #{2 3} (set/intersection #{1 2 3 4} #{2 3 5})) ;; J - Creates a new set of common elements.
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "But don't forget about the difference"
|
2016-02-27 20:53:16 +00:00
|
|
|
(= #{1 4} (set/difference #{1 2 3 4 5} #{2 3 5}))
|