Referencetap
Reference · 35
tap
tap
A side effect that doesn't change the value.
Signature
tap(observerOrNext?: Partial> | ((value: T) => void)): MonoTypeOperatorFunction
Marble diagram
in: --1--2--|
result: --1--2--| (callback fired on each)
What it does
Calls a function for each next/error/complete; the stream passes through unchanged. You can pass either a single function (next only) or a full observer object.
When to use
Logging while debugging, updating UI flags (loading), recording analytics, dev-inspecting values in the middle of a pipe. Better than map for anything that doesn't return a new value.
Gotcha
tap is the place for side effects, but not for all of them. Don't modify the value "on the sly" (by mutating an object) — that surprises the subscriber.
See also
map, finalize
script.ts
CONSOLE · Console output
Hit Run to see the result...