Another option (and shameless self promotion) is the rollup family of functions in https://github.com/sbelak/huri
Your case would be: (rollup first identity second foos) => {:a ("foo" "baz"), :b ("bar")} On Friday, August 12, 2016 at 7:10:37 PM UTC+2, Erik Assum wrote: > > I’ve been working on a new project in java 8 at a new client where I’ve > been able to play with streams. > In doing so I’ve come across Collectors.groupingBy which has some > additional features that group-by doesn’t seem to have. > > Example: > Given > (def foos [[:a "foo"] [:b "bar"] [:a "baz"]]) > > (group-by first foos) > ;=> {:a [[:a "foo"] [:a "baz"]], :b [[:b "bar"]]} > > but I’d like the result to be > ;=> {:a ["FOO" "BAZ"] :b ["BAR”]} > > This is solved in javas stream api by something like this: > > List<List<String>> = [["a", "foo"], ["b" "bar"], ["a", "baz"]]; > > foos > .stream() > .collect(Collectors.groupingBy(e -> e.get(0), > Collectors.mapping(e -> e.get(1).toUpperCase(), > Collectors.toList()))); > > Where the key point is that Collectors.groupingBy accepts a mapping > function in which to map the values being grouped. > > So how would one go about writing this in Clojure? I could of-course write > something that mapped over the grouped map, > but I’d really like to write something like > > (defn mapping-group-by grouping-fn mapping-fn coll) > > but I have a suspicion that this already exists in some form already? > > Erik. -- 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.