sets done
This commit is contained in:
parent
9ea2e0473c
commit
5b234f8edf
1 changed files with 6 additions and 6 deletions
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
(meditations
|
||||
"You can create a set by converting another collection"
|
||||
(= #{3} (set __))
|
||||
(= #{3} (set '(3)))
|
||||
|
||||
"Counting them is like counting other collections"
|
||||
(= __ (count #{1 2 3}))
|
||||
(= 3 (count #{1 2 3}))
|
||||
|
||||
"Remember that a set is a *mathematical* set"
|
||||
(= __ (set '(1 1 2 2 3 3 4 4 5 5)))
|
||||
(= #{1 2 3 4 5} (set '(1 1 2 2 3 3 4 4 5 5)))
|
||||
|
||||
"You can ask clojure for the union of two sets"
|
||||
(= __ (set/union #{1 2 3 4} #{2 3 5}))
|
||||
(= #{1 2 3 4 5} (set/union #{1 2 3 4} #{2 3 5}))
|
||||
|
||||
"And also the intersection"
|
||||
(= __ (set/intersection #{1 2 3 4} #{2 3 5}))
|
||||
(= #{2 3} (set/intersection #{1 2 3 4} #{2 3 5}))
|
||||
|
||||
"But don't forget about the difference"
|
||||
(= __ (set/difference #{1 2 3 4 5} #{2 3 5})))
|
||||
(= #{1 4} (set/difference #{1 2 3 4 5} #{2 3 5})))
|
||||
|
|
|
|||
Loading…
Reference in a new issue