February 2020
Intermediate to advanced
412 pages
9h 36m
English
Let's modify our earlier example, where we buffered 50 integers into lists of size 8. This time, we will use the window() operator to buffer elements of each list as an Observable. We can reactively transform each batch into something else besides a collection. For example, we can concatenate emissions into strings using a pipe (|), as a separator, as shown in the following code:
import io.reactivex.rxjava3.core.Observable;public class Ch7_08 { public static void main(String[] args) { Observable.range(1, 50) .window(8) .flatMapSingle(obs -> obs.reduce("", (total, next) -> total + (total.equals("") ? "" : "|") + next)) .subscribe(System.out::println); }}
The output is as follows:
1|2|3|4|5|6|7|89|10|11|12|13|14|15|16 ...
Read now
Unlock full access