public static <T, Y> Collector<T, ?, Optional<T>>
    minBy(Function<T, Y> projection, Comparator<Y> comparator) {
        return Collectors.minBy((a, b) -> {
            Y element1 = projection.apply(a);
            Y element2 = projection.apply(b);

            return comparator.compare(element1, element2);
        });
    }
public static < T , Y > Collector < T , ? , Optional < T > > minBy ( Function < T , Y > projection , Comparator < Y > comparator ) { return Collectors . minBy ( ( a , b ) -> { Y element1 = projection . apply ( a ) ; Y element2 = projection . apply ( b ) ; return comparator . compare ( element1 , element2 ) ; } ) ; }
Find the item for which the supplied projection returns the minimum value (variant for non-naturally-comparable
projected values).
@param projection The projection to apply to each item.
@param comparator The comparator to use to compare the projected values.
@param <T> The type of each item.
@param <Y> The type of the projected value to compare on.
@return The collector.