The doOn*() operators
In the previous chapter, we've used the map()
operator a couple of times to just print to the console what's happening inside our Observable chains. However, this isn't very convenient. The map()
operator always needs to return a value that is passed further down the chain, and it can catch only onNext
signals.
That's why RxPHP has a couple of operators with the common prefix doOn*
:
doOnNext()
,ÂdoOnError()
,ÂdoOnCompleted()
: Each of these operators takes a callable as a parameter that is executed when they receive their respective signaldoOnEach()
: This operator takes an instance ofÂObserverInterface
as a parameter and executes its handlers for each signal
So these operators are very similar to the methods subscribeCallback()
and subscribe()
. The biggest advantage is in the way doOn*
operators work internally. They never modify the value going through and just execute our callables, which is ideal for quickly debugging Observable chains or to perform side-effects without...