Recently, I've started diving into the world of Rxjs and came across a tutorial by David Acosta on Rxjs operators. He mentioned that using the tap operator is useful when we don't need to alter the data of an observable. The data inside the tap function remains unchanged.
I decided to try out the following code:
const source = Observable.of("david");
source.pipe(
tap(x => x.toString().toUpperCase())
).subscribe(x => console.log(x));
The output I received was david
.
However, running this code:
source.subscribe(x => console.log(x));
also resulted in the same output david
. This made me wonder why the tap operator is needed.
The concept seemed like a mystery to me as I struggled to find proper resources explaining the TAP
operator.
Can someone provide a detailed explanation on this and recommend some reliable tutorials or documentation for Rxjs operators?