June 2017
Intermediate to advanced
400 pages
8h 44m
English
Let's modify our earlier example, where we buffered 50 integers into lists of size 8, but we will use window() to buffer them as Observables instead. We can reactively transform each batch into something else besides a collection, such as concatenating emissions into strings with pipe "|" separators:
import io.reactivex.Observable;public class Launcher { 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|1617|18|19|20|21|22|23|2425|26|27|28|29|30|31|3233|34|35|36|37|38|39|4041|42|43|44|45|46|47|4849|50 ...
Read now
Unlock full access