If you are interested in learning about additional operators beyond what RxJava provides, it may be worthwhile to explore the RxJava2-Extras and RxJava2Extensions libraries. While neither of these libraries are at a 1.0 version, useful operators, Transformers, and Observable
/Flowable
factories are continually added as an ongoing project.
Two useful operators are toListWhile()
and collectWhile()
. These will buffer emissions into a list or collection while they meet a certain condition. Because a BiPredicate
passes both the list/collection and the next T
item as lamda input parameters, you can use this to buffer items but cut off the moment something changes about the emissions. Here, we keep collecting strings into a list but push that list forward when the length changes (kind of like distinctUntilChanged()
). We also will qualify a list being empty, as that is the start of the next buffer, as well as sample an item from the list to compare lengths...