vec creates a new persistent vector from a seqable or iterable collection, Java array, or nil. Ordered inputs retain their order; sets and maps do not promise one. section 12.5
Use vec when a vector is the useful boundary for collection data:
- Convert lists, lazy sequences, ranges, sets, maps, Java iterables, and arrays into vector values. section 12.5
- Treat transients and structs as exceptions; inputs that cannot become sequences throw a RuntimeException. section 12.5
- Remember that small reference-type Java arrays may be aliased, so later array mutation can change the apparent vector value. section 12.5
Array aliasing
(def a (make-array Long 3)) (def v (vec a)) (aset a 1 99) ;; v becomes [nil 99 nil] Primitive arrays behave differently: (def a (long-array 3)) (def v (vec a)) (aset a 1 99) ;; v remains [0 0 0]
