Since variety is the spice of life, here's my (less clean and untested) code that I was about to post when your message arrived in my inbox:
(apply map #(into {} %) (for [[k vs] args] (for [v vs] [k v])))) -Per On Thu, Oct 7, 2010 at 3:18 PM, Jason Wolfe <jawo...@berkeley.edu> wrote: > (defn d-map [& args] > (apply map > (fn [& vals] (zipmap (map first args) vals)) > (map second args))) > > On Oct 7, 12:54 am, Stefan Rohlfing <stefan.rohlf...@gmail.com> wrote: >> Thank you all for your great code examples! >> >> The goal of the function 'd-map' is to return a collection of maps >> that looks like this: >> >> ({:headline "this", :points 1, :comments 10} >> {:headline "is", :points 2, :comments 20} >> {:headline "me", :points 3, :comments 30}) >> >> Based on Per's example using 'for' I came up with the following >> implementation: >> >> (d-map [:headline ["this" "is" "me"] ] >> [:points [1 2 3] ] >> [:comments [10 20 30] ]) >> >> (defn d-map [& args] >> (let [kv-list (for [ [head items] args, item items] [head item]) >> len (count args)] >> (map #(into {} %) >> (partition len (apply interleave (partition len kv- >> list)))))) >> >> This is quite a few functions for turning 'kv-list': >> >> ([:headline "this"] [:headline "is"] [:headline "me"] [:points 1] >> [:points 2] ...) >> >> into: >> ({:headline "this", :points 1, :comments 10} {:headline "is", :points >> 2, ...} ...) >> >> Therefore, I would like to ask again if there is a more elegant way to >> get to this result. >> >> Stefan > > -- > 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 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