What would be the best way to query if a stream has been consumed? Was something akin to Stream::isConsumed
ever considered?
I acknowledge this being similar to the following question:
How to check if a Java 8 Stream is empty?
Albeit, the difference seems that checking for stream consumption seems not require partial consumption of said stream. Do the answers of the link above also apply here?
My use case is similar to the following:
/**
... This operation ensures, regardless whether the prefix or suffix stream is
parallel, that the suffix stream is computed only after the prefix stream has
been exhausted...
*/
public static <E> Stream<E> andThen(
Stream<? extends E> stream,
Supplier<? extends Stream<? extends E>> after);
EDIT (4/23/18) showing implementation details were not as important.
In andThen
, stream
must exhaust before appending the remaining elements produced by after
.
Granted, some may prefer writing a Spliterator
, but even then if writing trySplit
you may want to know if the children split from the prefix spliterator have exhausted their elements (blocking if not...?) before splitting the suffix; you probably would not want to prematurely consume any prefix elements to do so.
Related slightly; probably orthogonal; would a peeking spliterator be useful at all?
abstract boolean tryPeek(Consumer<? super E> action);
abstract boolean skip();
default boolean tryAdvance(Consumer<? super E> action) {return tryPeek(action) && skip();}