doOnNext
operator called every time when source Observable
emits an item. It can be used for debugging purposes, applying some action to the emitted item, logging, etc...
Observable.range(1, 3)
.doOnNext(value -> System.out.println("before transform: " + value))
.map(value -> value * 2)
.doOnNext(value -> System.out.println("after transform: " + value))
.subscribe();
In the example below doOnNext
is never called because the source Observable
emits nothing because Observable.empty()
calls onCompleted
after subscribing.
Observable.empty()
.doOnNext(item -> System.out.println("item: " + item))
.subscribe();