/** * Collects the underlying value(s) (if present) using the provided {@code collector}. * * @param <A> the mutable accumulation type of the reduction operation * @param <R> the result type of the reduction operation * @param collector Collector performing reduction * @return R reduction result */ default <R, A> R collect(Collector<? super T, A, R> collector) { return StreamSupport.stream(spliterator(), false).collect(collector); }
/** * Collects the underlying value(s) (if present) using the given {@code supplier}, {@code accumulator} and * {@code combiner}. * * @param <R> type of the result * @param supplier provide unit value for reduction * @param accumulator perform reduction with unit value * @param combiner function for combining two values, which must be * compatible with the accumulator. * @return R reduction result */ default <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner) { return StreamSupport.stream(spliterator(), false).collect(supplier, accumulator, combiner); }
/** * Converts this to a parallel {@link java.util.stream.Stream} by calling * {@code StreamSupport.stream(this.spliterator(), true)}. * * <pre>{@code * // empty Stream * Future.of(() -> { throw new Error(); }) * .toJavaParallelStream() * * // Stream containing "ok" * Try.of(() -> "ok") * .toJavaParallelStream() * * // Stream containing 1, 2, 3 * List.of(1, 2, 3) * .toJavaParallelStream() * }</pre> * * @return A new parallel {@link java.util.stream.Stream}. * @see Value#spliterator() */ default java.util.stream.Stream<T> toJavaParallelStream() { return StreamSupport.stream(spliterator(), true); }
/** * Converts this to a sequential {@link java.util.stream.Stream} by calling * {@code StreamSupport.stream(this.spliterator(), false)}. * * <pre>{@code * // empty Stream * Future.of(() -> { throw new Error(); }) * .toJavaStream() * * // Stream containing "ok" * Try.of(() -> "ok") * .toJavaStream() * * // Stream containing 1, 2, 3 * List.of(1, 2, 3) * .toJavaStream() * }</pre> * * @return A new sequential {@link java.util.stream.Stream}. * @see Value#spliterator() */ default java.util.stream.Stream<T> toJavaStream() { return StreamSupport.stream(spliterator(), false); }
/** * Collects the underlying value(s) (if present) using the provided {@code collector}. * * @param <A> the mutable accumulation type of the reduction operation * @param <R> the result type of the reduction operation * @param collector Collector performing reduction * @return R reduction result */ default <R, A> R collect(Collector<? super T, A, R> collector) { return StreamSupport.stream(spliterator(), false).collect(collector); }
/** * Collects the underlying value(s) (if present) using the given {@code supplier}, {@code accumulator} and * {@code combiner}. * * @param <R> type of the result * @param supplier provide unit value for reduction * @param accumulator perform reduction with unit value * @param combiner function for combining two values, which must be * compatible with the accumulator. * @return R reduction result */ default <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner) { return StreamSupport.stream(spliterator(), false).collect(supplier, accumulator, combiner); }
/** * Converts this to a sequential {@link java.util.stream.Stream} by calling * {@code StreamSupport.stream(this.spliterator(), false)}. * * <pre>{@code * // empty Stream * Future.of(() -> { throw new Error(); }) * .toJavaStream() * * // Stream containing "ok" * Try.of(() -> "ok") * .toJavaStream() * * // Stream containing 1, 2, 3 * List.of(1, 2, 3) * .toJavaStream() * }</pre> * * @return A new sequential {@link java.util.stream.Stream}. * @see Value#spliterator() */ default java.util.stream.Stream<T> toJavaStream() { return StreamSupport.stream(spliterator(), false); }
/** * Converts this to a parallel {@link java.util.stream.Stream} by calling * {@code StreamSupport.stream(this.spliterator(), true)}. * * <pre>{@code * // empty Stream * Future.of(() -> { throw new Error(); }) * .toJavaParallelStream() * * // Stream containing "ok" * Try.of(() -> "ok") * .toJavaParallelStream() * * // Stream containing 1, 2, 3 * List.of(1, 2, 3) * .toJavaParallelStream() * }</pre> * * @return A new parallel {@link java.util.stream.Stream}. * @see Value#spliterator() */ default java.util.stream.Stream<T> toJavaParallelStream() { return StreamSupport.stream(spliterator(), true); }