On Wed, Nov 18, 2009 at 8:19 AM, Robert Campbell <rrc...@gmail.com> wrote: > Hey guys, > > I'm having some trouble finding a nice way to perform a map > transformation I need. I need to transform this: > > [ {:a 1 :b 2 :c 3} {:a 4 :b 5 :c 6} {:a 7 :b 8 :c 9} ] > > into this: > > { {:a 1 :b 2} 3 {:a 4 :b 5} 6 {:a 7 :b 8} 9 } > > I wanted to use map, but each f in map only returns one value, so I > couldn't figure it out. Here is what I have now: > > (def result (ref {})) > (for [item coll] > (dosync (alter result assoc (dissoc item :c) (item :c)))) > ; result should now have correct value > > I also wrote a recursive version to build the map without using a ref, > but I feel like I'm missing a simpler way.. >
(into {} (map (fn [m] [(dissoc m :c) (:c m)]) [{:a 1 :b 2 :c 3} {:a 4 :b 5 :c 6} {:a 7 :b 8 :c 9}])) -> {{:a 1, :b 2} 3, {:a 4, :b 5} 6, {:a 7, :b 8} 9} Rich -- 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