Is there a concise way to extract both the min and max value of a stream (based on some comparator) in one pass?
There appear to be many ways to get the min and max
A straightforward approach using any mutable Pair class:
final Pair pair = new Pair<>();
final Comparator comparator = ...;
Stream.of(...).forEachOrdered(e -> {
if(pair.first == null || comparator.compare(e, pair.first) < 0){
pair.first = e;
}
if(pair.second == null || comparator.compare(e, pair.second) > 0){
pair.second = e;
}
});