Sorry, I got the semantics of the grouping-fn wrong. My code assumes that the key is always first in the elements and my grouping is more like a merging-fn.
> On Aug 14, 2016, at 2:53 PM, miner <stevemi...@gmail.com> wrote: > > If your data elements are essentially map-entries (key-value pairs), I'd use > reduce. Maybe something like this would work for you... > > (defn mapping-group-by [grouping-fn mapping-fn coll] > (reduce (fn [res [k v]] (update res k grouping-fn (mapping-fn v))) > {} > coll)) > > (def foos [[:a "foo"] [:b "bar"] [:a "baz"]]) > > (mapping-group-by conj clojure.string/upper-case foos) > ;;=> {:a ("BAZ" "FOO"), :b ("BAR")} > > If you need vector values, you can wrap `conj` with `fnil` to get a vector. > > (mapping-group-by (fnil conj []) clojure.string/upper-case foos) > ;;=> {:a ["FOO" "BAZ"] :b ["BAR"]} > > > -- > 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 > <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 > <mailto:clojure+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- 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/d/optout.