Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested addition: replace-subvec #82

Open
jramosg opened this issue Nov 16, 2023 · 1 comment
Open

Suggested addition: replace-subvec #82

jramosg opened this issue Nov 16, 2023 · 1 comment

Comments

@jramosg
Copy link

jramosg commented Nov 16, 2023

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))))
@weavejester
Copy link
Owner

This function might be a little too specific for Medley.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants