Thanks BG, I prefer your version. I'd forgotten about select-keys.
Cheers, David On 4 April 2012 15:20, Baishampayan Ghose <b.gh...@gmail.com> wrote: >> Please have a look at the following function (explained in the doc >> string). I have a bunch of rows that I need to aggregate using >> different functions per field. I also need to apply the aggregate to a >> subset of the rows. Obviously this is just like SQL aggregation, hence >> the interface I've specified. >> >> However I'm left wondering whether my implementation could be improved. >> >> Particularly I very often find myself doing >> >> (apply hash-map (flatten (for [[k v] some-map] ...))) >> >> so often in fact that I feel like I'm missing something. >> >> Any pointers or advice on improving my style will be much appreciated! > > Don't have a direct answer to your question, but what about > implementing aggregate like this - > > (defn aggregate [rows & {select :select where :where}] > (let [projection (apply merge-with vector (map #(select-keys % > (keys select)) (filter where rows)))] > (reduce (fn [agg [k v]] (assoc agg k (apply (select k) v))) {} > projection))) > > Regards, > BG > > -- > Baishampayan Ghose > b.ghose at gmail.com > > -- > 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 -- David Jagoe davidja...@gmail.com +447535268218 -- 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