Now that you know about Clojure's general collection properties and the sequence abstraction, it is a good time to get to know about Clojure's specific collection implementations.
Vectors are Clojure's workhorse; together with map, it is the most used collection. Don't be afraid of them; they have nothing to do with Java's java.util.Vector
. They are just a series of ordered values, such as a list or an array.
They have the following properties:
They are immutable
They can be accessed sequentially
They are associative (they are maps of their indices, meaning that their keys are 0, 1, 2, and so on)
They are counted, meaning they have a finite size
They have random access, so you can access any element with almost constant time (with the nth function)
The
conj
function appends a given element to them