This probably won't help with your garbage collection worries, but it's a bit more flexible.
*(defn find-assoc-in [pred coll k v & kvs]* * (let [f #(if (pred %) (apply assoc % k v kvs) %)]* * (into (empty coll) (map f coll))))* On Tuesday, July 30, 2013 10:53:48 AM UTC-7, cej38 wrote: > > 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.