Beta (still building)

tap

tap operator used to do side effect for every emission (next, complete and error)

we can pass a function to perform a side effect for next emission

or pass an observer to perform side effects for next, complete or error emission

Example: tap operator side effect with next emission

open the inspector, you will see many logs because the observable has extra subscriptions

import { interval } from 'rxjs';
import { tap, take } from 'rxjs/operators';

const source$ = interval(1500).pipe(take(4));
const result$ = source$.pipe(
  tap(i => console.log(`Example tap: ${i}`)),
);

Example: tap operator with observer

observer {next: () => {}, error: () => {}, complete: () => {}}

import { interval } from 'rxjs';
import { tap, take } from 'rxjs/operators';

const source$ = interval(1500).pipe(take(4));
const result$ = source$.pipe(
  tap({
   next: (i) => console.log(i),
   error: (e) => console.error(e),
   complete: () => console.warn('complete')
  }),
);

Official Doc: rxjs.tap