June 2017
Intermediate to advanced
400 pages
8h 44m
English
The scan() method is a rolling aggregator. For every emission, you add it to an accumulation. Then, it will emit each incremental accumulation.
For instance, you can emit the rolling sum for each emission by passing a lambda to thescan() method that adds each next emission to the accumulator:
import io.reactivex.Observable; public class Launcher { public static void main(String[] args) { Observable.just(5, 3, 7, 10, 2, 14) .scan((accumulator, next) -> accumulator + next) .subscribe(s -> System.out.println("Received: " + s)); } }
The output of the preceding code snippet is as follows:
Received: 5Received: 8Received: 15Received: 25Received: 27Received: 41
It emitted the initial value of 5, which was the first emission it received. Then, ...
Read now
Unlock full access