Clojure Remove item from Vector at a Specified Location
subvec
is probably the best way. The Clojure docs say subvec
is "O(1) and very fast, as the resulting vector shares structure with the original and no trimming is done". The alternative would be walking the vector and building a new one while skipping certain elements, which would be slower.
Removing elements from the middle of a vector isn't something vectors are necessarily good at. If you have to do this often, consider using a hash-map so you can use dissoc
.
See:
- subvec at
clojuredocs.org
- subvec at
clojure.github.io
, where the official website points to.
(defn vec-remove
"remove elem in coll"
[pos coll]
(into (subvec coll 0 pos) (subvec coll (inc pos))))