doOnSuccess()

Remember that Maybe and Single types do not have an onNext() event but rather an onSuccess() operator to pass a single emission. Therefore, there is no doOnNext() operator on either of these types, as observed in the following code snippet, but rather a doOnSuccess() operator. Its usage should effectively feel like doOnNext():

import io.reactivex.Observable;public class Launcher {      public static void main(String[] args) {        Observable.just(5, 3, 7, 10, 2, 14)          .reduce((total, next) -> total + next)          .doOnSuccess(i -> System.out.println("Emitting: " + i))          .subscribe(i -> System.out.println("Received: " + i));      }}

The output of the preceding code snippet is as follows:

    Emitting: 41    Received: 41

Get Learning RxJava now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.