Suppose I have a vector of maps (this could also be a vector of records)

(def aa [{:a 0 :b 0 :c 0} {:a 50 :b 0 :c 0} {:a 100 :b 0 :c 0}])

and I want to go in an change the value of associated with :c when :a has a 
value of 50, so that the final col of maps looks like

[{:a 0 :b 0 :c 0} {:a 50 :b 0 :c 3} {:a 100 :b 0 :c 0}].



I came up with a function that does this:

(defn find-assoc-in
  [k v  mv]
  (let [f #(if (= ((first k) %) (first v))
             (assoc % (second k) (second v))
             %)]
     (map f mv)))


(find-assoc-in [:a :c] [50 3] aa)    


The problem with this function is that it potentially does a lot 
of unnecessary copying of elements that aren't changed, and thus has a lot 
of garbage collection.  I would like help coming up with something that 
does much less garbage collection.


Will someone please point out a better way of doing this?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to