June 2017
Intermediate to advanced
400 pages
8h 44m
English
The simplest operator to consolidate emissions into a single one is count(). It will count the number of emissions and emit through a Single once onComplete() is called, shown as follows:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon") .count() .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: 5
Like most reduction operators, this should not be used on an infinite Observable. It will hang up and work infinitely, never emitting a count or calling onComplete(). You should consider using scan() to emit a rolling count instead.
Read now
Unlock full access