3 ms·
I've not yet worked on anything more recent than 8 but ... I have a Map of Lists of Foo items (foos), and I want to transform each item in the sublists to a Ba
by Nursie 7y ago
I've not yet worked on anything more recent than 8 but ...
I have a Map of Lists of Foo items (foos), and I want to transform each item in the sublists to a Bar, filter out bad Bars, transform to Baz and keep the results as a new list of Bazs
List<Baz> barList = foos.values()
.stream()
.flatMap(List::stream)
.map(Foo::transformToBar)
.filter(Bar::isBad)
.map(Baz::transformToBaz)
.collect(Collectors.toList());
The syntax is a little clunky at times... but once you get used to it it's quite expressive.