Let's say I have a stream of following object.
class MyObject {
private Some some; // Comparable
private Other value
}
Is there any idiom doing following things in a single chain?
- With given
Stream<MyObject>, - Finds the maximum value of
some. - Map
values whosesomeis the maximum.
as if,
final List<MyObject> list = getList();
final Some max = list.stream().max(Comparator.naturalOrder())
final List<Other> list = list.stream()
.filter(e -> Objects.equals(e.some, max)
.map(e -> e.getValue()).collect(toList());