June 2017
Intermediate to advanced
400 pages
8h 44m
English
Another variant of the take() operator is the takeWhile() operator, which takes emissions while a condition derived from each emission is true. The following example will keep taking emissions while emissions are less than 5. The moment it encounters one that is not, it will call the onComplete() function and dispose of this:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.range(1,100) .takeWhile(i -> i < 5) .subscribe(i -> System.out.println("RECEIVED: " + i)); }}
The output of the preceding code snippet is as follows:
RECEIVED: 1RECEIVED: 2RECEIVED: 3RECEIVED: 4
Just like the takeWhile() function, there is a skipWhile() function. It will keep skipping ...
Read now
Unlock full access