The Clojure function vector creates a persistent vector containing its arguments in the order received. With known elements, the literal [] is shorter and idiomatic; vector is useful when arguments must be collected dynamically. section 12.4
Its contract is straightforward:
- Accepts zero or more arguments, including nil and other vectors. section 12.4
- Returns a clojure.lang.PersistentVector; zero arguments produce an empty vector. section 12.4
- Supports specialized arities from zero through six arguments, then a variadic arity. section 12.4
Literal versus function
(vector :a :b :c) ;; [:a :b :c] [:a :b :c] ;; [:a :b :c] (defn var-args [a b & all] (apply vector a b all)) (var-args :a :b :c) ;; [:a :b :c]
Composing vectors with map
(def m [[1 2 3] [4 5 6] [7 8 9]]) (apply map vector m) ;; ([1 4 7] ;; [2 5 8] ;; [3 6 9])
