February 2020
Intermediate to advanced
412 pages
9h 36m
English
The count() operator counts the number of emitted items and emits the result through a Single once onComplete() is called. Here is an example:
import io.reactivex.rxjava3.core.Observable;public class Ch3_22 { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma") .count() .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: 3
Like most reduction operators, this should not be used on an infinite Observable. It will hang up and work indefinitely, never emitting a count or calling onComplete(). If you need to count emissions of an infinite Observable, consider using scan() to emit a rolling count instead.
Read now
Unlock full access