@Override public OptionalDouble max() { return reduce(Math::max); }
@Override public OptionalDouble min() { return reduce(Math::min); }
/** * Returns the maximum element of this stream according to the provided * {@code Comparator}. * * <p> * This is a terminal operation. * * @param comparator a non-interfering, stateless {@link Comparator} to * compare elements of this stream * @return an {@code OptionalDouble} describing the maximum element of this * stream, or an empty {@code OptionalDouble} if the stream is empty */ public OptionalDouble max(Comparator<Double> comparator) { return reduce((a, b) -> comparator.compare(a, b) >= 0 ? a : b); }
/** * Returns the minimum element of this stream according to the provided * {@code Comparator}. * * <p> * This is a terminal operation. * * @param comparator a non-interfering, stateless {@link Comparator} to * compare elements of this stream * @return an {@code OptionalDouble} describing the minimum element of this * stream, or an empty {@code OptionalDouble} if the stream is empty * @since 0.1.2 */ public OptionalDouble min(Comparator<Double> comparator) { return reduce((a, b) -> comparator.compare(a, b) > 0 ? b : a); }