Clojure Remove item from Vector at a Specified Location

后端 未结 8 902
无人共我
无人共我 2020-12-04 01:35

Is there a way to remove an item from a vector based on index as of now i am using subvec to split the vector and recreate it again. I am looking for the reverse of assoc fo

8条回答
  •  心在旅途
    2020-12-04 02:10

    The vector library clojure.core.rrb-vector provides logarithmic time concatenation and slicing. Assuming you need persistence, and considering what you're asking for, a logarithmic time solution is as fast as theoretically possible. In particular, it is much faster than any solution using clojure's native subvec, as the concat step puts any such solution into linear time.

    (require '[clojure.core.rrb-vector :as fv])
    (let [s (vec [0 1 2 3 4])]
      (fv/catvec (fv/subvec s 0 2) (fv/subvec s 3 5)))
    ; => [0 1 3 4]
    

提交回复
热议问题