Merge pull request #7 from latacora/revert-6-04-05-Vector-Sets
Revert " Vector and Sets clj completed"
This commit is contained in:
commit
ed3da94815
2 changed files with 16 additions and 16 deletions
|
|
@ -3,31 +3,31 @@
|
|||
|
||||
(meditations
|
||||
"You can use vectors in clojure as array-like structures"
|
||||
(= 1 (count [42]))
|
||||
(= __ (count [42]))
|
||||
|
||||
"You can create a vector from a list"
|
||||
(= [1] (vec '(1)))
|
||||
(= __ (vec '(1)))
|
||||
|
||||
"Or from some elements"
|
||||
(= [nil nil] (vector nil nil))
|
||||
(= __ (vector nil nil))
|
||||
|
||||
"But you can populate it with any number of elements at once"
|
||||
(= [1 2 ] (vec '(1 2)))
|
||||
(= [1 __] (vec '(1 2)))
|
||||
|
||||
"Conjoining to a vector is different than to a list"
|
||||
(= [111 222 333] (conj [111 222] 333))
|
||||
(= __ (conj [111 222] 333))
|
||||
|
||||
"You can get the first element of a vector like so"
|
||||
(= :peanut (first [:peanut :butter :and :jelly]))
|
||||
(= __ (first [:peanut :butter :and :jelly]))
|
||||
|
||||
"And the last in a similar fashion"
|
||||
(= :jelly (last [:peanut :butter :and :jelly]))
|
||||
(= __ (last [:peanut :butter :and :jelly]))
|
||||
|
||||
"Or any index if you wish"
|
||||
(= :jelly (nth [:peanut :butter :and :jelly] 3))
|
||||
(= __ (nth [:peanut :butter :and :jelly] 3))
|
||||
|
||||
"You can also slice a vector"
|
||||
(= [:butter :and](subvec [:peanut :butter :and :jelly] 1 3))
|
||||
(= __ (subvec [:peanut :butter :and :jelly] 1 3))
|
||||
|
||||
"Equality with collections is in terms of values"
|
||||
(= (list 1 2 3) (vector 1 2 3)))
|
||||
(= (list 1 2 3) (vector 1 2 __)))
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
(meditations
|
||||
"You can create a set by converting another collection"
|
||||
(= #{3} (set [3]))
|
||||
(= #{3} (set __))
|
||||
|
||||
"Counting them is like counting other collections"
|
||||
(= 3 (count #{1 2 3}))
|
||||
(= __ (count #{1 2 3}))
|
||||
|
||||
"Remember that a set is a *mathematical* set"
|
||||
(= #{1 4 3 2 5} (set '(1 1 2 2 3 3 4 4 5 5)))
|
||||
(= __ (set '(1 1 2 2 3 3 4 4 5 5)))
|
||||
|
||||
"You can ask clojure for the union of two sets"
|
||||
(= #{1 2 3 4 5} (set/union #{1 2 3 4} #{2 3 5}))
|
||||
(= __ (set/union #{1 2 3 4} #{2 3 5}))
|
||||
|
||||
"And also the intersection"
|
||||
(= #{2 3} (set/intersection #{1 2 3 4} #{2 3 5}))
|
||||
(= __ (set/intersection #{1 2 3 4} #{2 3 5}))
|
||||
|
||||
"But don't forget about the difference"
|
||||
(= #{1 4} (set/difference #{1 2 3 4 5} #{2 3 5})))
|
||||
(= __ (set/difference #{1 2 3 4 5} #{2 3 5})))
|
||||
|
|
|
|||
Loading…
Reference in a new issue