The basic abstraction that I see, is that you need a function that
will replace a range within a collection with another collection.
Here's a quick and dirty way of doing that:
(defn assoc-range [v min max v2]
(vec (concat
(take min v)
v2
(nthnext v (dec max)))))
So calling:
(assoc-range [0 1 2 3 4] 2 4 ["a" "b"])
returns:
[0 1 "a" "b" 3 4]
So now you can write your original code as this:
(assoc-range a-vector k (- (count a-vector) k)
(map modify-element a-vector))
This should be quite a bit faster than your original code. And is a
little cleaner in my opinion.
Hope that helps
-Patrick
PS: And perhaps you can find a more elegant way of writing assoc-
range. Mine is a little smelly.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en