Substitute for groupingReduce ?
Brian Goetz
brian.goetz at oracle.com
Wed Mar 20 12:36:20 PDT 2013
I think you're missing a reduce function in that call? I see a
classifying function and a merge function.
But here are some possible answers:
Cities by name:
Map<String, List<City>> citiesByName
= cities.stream().collect(groupingBy(City::getName));
Total population by name:
Map<String, Integer> cityPopsByName
= cities.stream()
.collect(groupingBy(City::getName,
reducing(City::getPop, Integer::sum));
Biggest city by name:
Comparator<City> bySize = Comparators.comparing(City::getPop);
Map<String, City> biggestCityByName
= cities.stream()
.collect(groupingBy(City::getName,
reducing(greaterOf(bySize)));
On 3/20/2013 3:24 PM, Michael Nascimento wrote:
> Hi guys,
>
> I had this before:
>
> Map<String, City> cityByName = cities.stream().collect(groupingReduce(
> city -> city.getName(), throwingMerger()));
>
> What is the proper replacement?
>
> Regards,
> Michael
>
More information about the lambda-dev
mailing list