February 2020
Intermediate to advanced
412 pages
9h 36m
English
The doOnEach() operator is very similar to doOnNext(). The only difference is that in doOnEach(), the emitted item comes wrapped inside a Notification that also contains the type of the event. This means you can check which of the three events—onNext(), onComplete(), or onError()—has happened and select an appropriate action.
The subscribe() method accepts these three actions as lambda arguments or an entire Observer<T>. So, using doOnEach() is like putting subscribe() right in the middle of your Observable chain! Here is an example:
import io.reactivex.rxjava3.core.Observable;public class Ch3_54 { public static void main(String[] args) { Observable.just("One", "Two", "Three") .doOnEach(s -> System.out.println("doOnEach: " + s)) ...
Read now
Unlock full access