@Override public OptionalLong max() { return reduce(Long::max); }
@Override public long sum() { return reduce(0, Long::sum); }
@Override public OptionalLong min() { return reduce(Long::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 OptionalLong} describing the maximum element of this * stream, or an empty {@code OptionalLong} if the stream is empty */ public OptionalLong max(Comparator<Long> 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 OptionalLong} describing the minimum element of this * stream, or an empty {@code OptionalLong} if the stream is empty * @since 0.1.2 */ public OptionalLong min(Comparator<Long> comparator) { return reduce((a, b) -> comparator.compare(a, b) > 0 ? b : a); }