{:rank ["create" "destructure" "construct"]}
box
Chapter 3.5: Functions on Vectors
Clojure Cheatsheet: https://clojure.org/api/cheatsheet
; Creating vectors
[3 2 1 "Hello" "World"]
; Using the vector constructor function
(vector 3 2 1 "Hello" "World")
; Convert sequences to vector
(vec '(3 2 1 "Hello" "World"))
All list destructuring functions can be used for vectors.
; Let's make a vector first.
(def xs [3 2 1 "Hello" "World" :again :and :again])
(first xs)
(rest xs)
(last xs)
(nth xs 3)
It turns out that vectors can be used as functions over integers.
(xs n)
returns the n-th element.
(xs 3)
All sequence functions can be applied to vectors.
All sequence construction functions can be used for vectors, but with some subtle differences.
; Let's make a vector first.
(def xs [3 2 1 "Hello" "World" :again :and :again])
Recall (conj coll element)
addes the element to the collection
in the most efficient way.
(conj xs "NEW")
Same is true for (into coll elements)
(into xs ["NEW-1" "NEW-2" "NEW-3"])
Concat always returns a list regardless of its input collection types.
(concat xs ["NEW 1" "NEW 2"])