reactive-streams-utils
reactive-streams-utils copied to clipboard
Stream splitting
We might want to introduce some stream splitting functions. For example, a splitWhen function.
This functionality is generally only useful when doing parsing, where you parse some sort of header out of the stream, followed by a sub stream, then another header, etc.
Generally, the element that is split at needs to be accessed before consuming the sub stream. So the sub stream should make that element available, along with the rest of the stream. For example:
PublisherBuilder<SubStream<T>> splitWhen(Predicate<? super T> predicate);
class SubStream<T> {
final T first;
final PublisherBuilder<T> rest;
}
So, for each element where the predicate holds true (plus the first element), a SubStream is emitted, with first being that element, and rest being the remainder of the stream as long as the predicate holds false.