I'm trying to do grouping by (to map) and then transform list of values to different list.
I have List of DistrictDocuments:
List<DistrictDocument> docs = new ArrayList<>();
Then I'm streaming over it and grouping it by city:
Map<String, List<DistrictDocument>> collect = docs.stream()
.collect(Collectors.groupingBy(DistrictDocument::getCity));
I also have a method which takes DistrictDocument and creates Slugable out of it:
private Fizz createFizz(DistrictDocument doc) {
return new Fizz().name(doc.getName()).fizz(doc.getFizz());
}
Is there a way to put that method into my stream above so I get Map<String, List<Fizz>>
?
I tried adding 2nd argument to groupingBy but couldn't find a proper way and been always getting compilation errors.
Edit:
What if my createFizz returns List<Fizz>
? Is there an option to flat this list in Collectors.mapping becasue I still want to have Map<String, List<Fizz>>
instead of Map<String, List<List<Fizz>>>