On Tue, Jun 23, 2009 at 5:09 PM, samppi <rbysam...@gmail.com> wrote: > > The idiom (into {} coll-of-entries) is often used to create a map from > a collection of entries or two-sized vectors. But what if I want to do > something like this: > > (mystery-fn [[:a 1] [:b 3] [:b 5] [:c 1]]) ; returns {:a [1], :b [3 > 5], :c [1]}) >
(defn mystery-fn [coll] (reduce (fn [map [k v]] (assoc map k (conj (get map k []) v))) {} coll)) user=> (mystery-fn [[:a 1] [:b 3] [:b 5] [:c 1]]) {:c [1], :b [3 5], :a [1]} -- Cosmin Stejerean http://offbytwo.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 -~----------~----~----~----~------~----~------~--~---