medley icon indicating copy to clipboard operation
medley copied to clipboard

Suggested addition: replace-subvec

Open jramosg opened this issue 2 years ago • 1 comments

When you need to put a vector into another vector, from start until the end of the vector to insert.

(defn replace-subvec [v v2 index]
  {:pre [(vector? v)
         (vector? v2)
         (integer? index)]}
  (let [v-count (count v)
        index (if (<= index v-count)
                index v-count)]
    (persistent!
      (reduce-kv
        (fn [acc i el]
          (assoc! acc (+ i index) el))
        (transient v) v2))))

jramosg avatar Nov 16 '23 18:11 jramosg

This function might be a little too specific for Medley.

weavejester avatar Nov 16 '23 20:11 weavejester