February 2020
Intermediate to advanced
412 pages
9h 36m
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 generate the onComplete event and dispose of the used resources:
import io.reactivex.rxjava3.core.Observable;public class Ch3_01 { 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. ...
Read now
Unlock full access