I have a collection of transducers that I use in such cases:

(require '[net.cgrand.xforms :as x]
  '[clojure.string :as str])

(into {} (x/by-key (comp (map str/upper-case) (x/into [])))
;=> [[:a "foo"]  [:b "bar"]  [:a "baz"]])


On Fri, Aug 12, 2016 at 7:14 PM, Moe Aboulkheir <m...@nervous.io> wrote:

> As far as already existing, (grouped-map first (comp str/upper-case
> second) ...) or similar, with https://github.com/plumatic/
> plumbing/blob/master/src/plumbing/core.cljx#L164
>
> Take care,
> Moe
>
> On Fri, Aug 12, 2016 at 6:10 PM, Erik Assum <e...@assum.net> 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.
>>
>
> --
> 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.
>



-- 
On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/

-- 
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.

Reply via email to