Combine StreamSupport.stream/parallelStream?
Paul Sandoz
paul.sandoz at oracle.com
Fri Jun 28 07:44:29 PDT 2013
On Jun 27, 2013, at 10:43 PM, Brian Goetz <brian.goetz at Oracle.COM> wrote:
> A possible minor API cleanup:
>
> For each pair of low-level methods stream() and parallelStream() in StreamSupport, we could combine these into a single method that takes an additional boolean isParallel argument. This matches the underlying implementation they call anyway, and simplifies callers like concat, which now does:
>
Seems a reasonable thing to do.
The current approach matches nicely that on collection:
default Stream<E> stream() {
return StreamSupport.stream(spliterator());
}
default Stream<E> parallelStream() {
return StreamSupport.parallelStream(spliterator());
}
But that is actually a minority of usage. Most use of StreamSupport is for the stream() methods.
We could get away with just one less method per type for the supplying variant:
public static <T> Stream<T> stream(Spliterator<T> spliterator)
public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean isParallel)
public static <T> Stream<T> stream(Supplier<? extends Spliterator<T>> supplier,
int characteristics, boolean isParallel)
Paul.
More information about the lambda-libs-spec-observers
mailing list