Skip to content

filterMap

filterMap<T, R>(iterable, mapper): IterableIterator<R>

Defined in: packages/core/src/iterable/filter-map.ts:20

Maps and filters in one pass: yields every mapped value except the ones the mapper declines to produce.

undefined is the decline signal, and the result type cannot include it, so “no value here” is never confused with “the value is undefined”. That is what makes this different from .map(…).filter(…), which cannot tell the two apart and walks the sequence twice.

Time complexity: O(1) per element, plus whatever mapper costs.

T

R extends DefinedValue

Iterable<T>

The input iterable.

Callable<[T, number], R | undefined>

Receives each element and its zero-based index. Returns the mapped value, or undefined to drop the element.

IterableIterator<R>

An iterator over the produced values.