February 2020
Intermediate to advanced
412 pages
9h 36m
English
As you might be able to guess, you can cut off a windowed Observable at a time interval just like we did with the buffer() operator. For example, let's create an Observable that emits every 300 milliseconds and then slice it into separate observables every 1 second. We will then use flatMapSingle() on each Observable to build up a String concatenation of the emissions, as the following code demonstrates:
import io.reactivex.rxjava3.core.Observable;import java.util.concurrent.TimeUnit;public class Ch7_10 { public static void main(String[] args) { Observable.interval(300, TimeUnit.MILLISECONDS) .map(i -> (i + 1) * 300) .window(1, TimeUnit.SECONDS) .flatMapSingle(obs -> obs.reduce("", (total, next) -> total + (total.equals( ...
Read now
Unlock full access