reactive-streams-utils icon indicating copy to clipboard operation
reactive-streams-utils copied to clipboard

Stream splitting

Open jroper opened this issue 7 years ago • 0 comments

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.

jroper avatar Mar 19 '18 06:03 jroper