public OptionalDouble maxByInt(DoubleToIntFunction keyExtractor) {
        return collect(PrimitiveBox::new, (box, d) -> {
            int key = keyExtractor.applyAsInt(d);
            if (!box.b || box.i < key) {
                box.b = true;
                box.i = key;
                box.d = d;
            }
        }, PrimitiveBox.MAX_INT).asDouble();
    }
public OptionalDouble maxByInt ( DoubleToIntFunction keyExtractor ) { return collect ( PrimitiveBox :: new , ( box , d ) -> { int key = keyExtractor . applyAsInt ( d ) ; if ( ! box . b || box . i < key ) { box . b = true ; box . i = key ; box . d = d ; } } , PrimitiveBox . MAX_INT ) . asDouble ( ) ; }
Returns the maximum element of this stream according to the provided key
extractor function.

<p>
This is a terminal operation.

@param keyExtractor a non-interfering, stateless function
@return an {@code OptionalDouble} describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty {@code OptionalDouble} if the stream is empty
@since 0.1.2