I have a stream of objects and I would like to find the one with a maximal value of some attribute that\'s expensive to calculate.
As a specific simple example, say
Here's a variant using an Object[] as a tuple, not the prettiest code but concise
Object[]
String coolestString = stringList .stream() .map(s -> new Object[] {s, coolnessIndex(s)}) .max(Comparator.comparingInt(a -> (int)a[1])) .map(a -> (String)a[0]) .orElse(null);