I have a vector v
(def v [1 2 5 8 4 3 8 9 3])
I want to apply function myfn
(defn myfn [x] (+ 1 x))
to selected items that I have their indexes idx
(def idx [3 5])
I’ve seen How do I modify a portion of a vector in Clojure? and it is not exactly what I need.
Like what you do in MATLAB
v = [1 2 5 8 9 3];
idx = [3 5];
v(idx) = myfn(v(idx));
Vectors in clojure are associative, so you can do something like this:
(reduce #(update-in %1 [%2] myfn) v idx)