June 2017
Intermediate to advanced
400 pages
8h 44m
English
The reduce() operator is syntactically identical to scan(), but it only emits the final accumulation when the source calls onComplete(). Depending on which overload you use, it can yield Single or Maybe. If you want to emit the sum of all integer emissions, you can take each one and add it to the rolling total. But it will only emit once it is finalized:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just(5, 3, 7, 10, 2, 14) .reduce((total, next) -> total + next) .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: 41
Similar to scan(), there is a seed argument that you can provide that will serve as ...
Read now
Unlock full access