The simplest example would be a stream of strings like this:
["3", "a", "b", "c", "1", "a", "2", "a", "b"] The ones that are numbers describe how many more elements should it's group contain.
Very important that the stream is continuous so we cant just wait for the next number to split the stream.
As far as I know there is no built in functionality for this in RXJava2
var flowable = Flowable.concat(Flowable.fromArray("3", "a", "b", "c", "1", "a", "2", "a", "b"), Flowable.never()); flowable/*Something here*/.blockingSubscribe(System.out::println); And the expected output would be:
[3, a, b, c] [1, a] [2, a, b]