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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.