BACK
Reference · 09

map

Transforms each value of the stream.

Signature

map(project: (value: T, index: number) => R): OperatorFunction

Marble diagram

in:    --1--2--3--|
map*10: --10-20-30-|

What it does

Applies a pure function to each next and emits the result. The project function's second parameter is the emission index (from zero), handy for numbering.

When to use

Any pure value transformation: parsing JSON, picking a field (map(r => r.data)), formatting, DTO → ViewModel. It's the first operator you reach for, and it's often enough.

Gotcha

If the function throws, the stream fails with error. For side effects that don't change the value, use tap, not map.

See also

tap, switchMap, scan

script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...