tap vs map code example

Example 1: rxjs mapto vs tap

const source$ = of(1,2,3) // observable which will emit 1,2,3
// It take an input observable and return a same observable after console value.
// So, the output observable will emit 1,2,3
const tapSource$ = of(1,2,3)
                    .pipe(tap(value => console.log(value)))

Example 2: rxjs mapto vs tap

const source$ = of(1,2,3) // observable which will emit 1,2,3
// It take an input observable and return a new observable which will emit square of input values. 
// So, the output observable will emit 1,4,9
const mapSource$ = of(1,2,3)
                    .pipe(map(value => value * value))

Tags:

Misc Example