public OptionalInt maxByDouble(IntToDoubleFunction keyExtractor) {
        return collect(PrimitiveBox::new, (box, i) -> {
            double key = keyExtractor.applyAsDouble(i);
            if (!box.b || Double.compare(box.d, key) < 0) {
                box.b = true;
                box.d = key;
                box.i = i;
            }
        }, PrimitiveBox.MAX_DOUBLE).asInt();
    }
public OptionalInt maxByDouble ( IntToDoubleFunction keyExtractor ) { return collect ( PrimitiveBox :: new , ( box , i ) -> { double key = keyExtractor . applyAsDouble ( i ) ; if ( ! box . b || Double . compare ( box . d , key ) < 0 ) { box . b = true ; box . d = key ; box . i = i ; } } , PrimitiveBox . MAX_DOUBLE ) . asInt ( ) ; }
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 OptionalInt} describing the first element of this
stream for which the highest value was returned by key extractor,
or an empty {@code OptionalInt} if the stream is empty
@since 0.1.2