clojure.core/subvec¶
Returns a persistent vector of the items in vector from start (inclusive) to end (exclusive). If end is not supplied, defaults to (count vector). This operation is O(1) and very fast, as the resulting vector shares structure with the original and no trimming is done.
Examples¶
Note by reborg¶
;; Note that subvec holds a reference to the original vector. If you plan
;; to split a large vector and never using it again, consider freeing up
;; the reference.
(let [v1 (subvec (vec (range 1e7)) 0 5)
v2 (subvec (vec (range 1e7)) 5 10)]
(into v1 v2))
;; OutOfMem
(let [v1 (into [] (subvec (vec (range 1e7)) 0 5))
v2 (into [] (subvec (vec (range 1e7)) 5 10))]
(into v1 v2))
;; [0 1 2 3 4 5 6 7 8 9]
See also¶
Content from the matching ClojureDocs page, with authors credited on each contribution.