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.
Type Parameters
Section titled “Type Parameters”T
R extends DefinedValue
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The input iterable.
mapper
Section titled “mapper”Callable<[T, number], R | undefined>
Receives each element and its zero-based index. Returns the
mapped value, or undefined to drop the element.
Returns
Section titled “Returns”IterableIterator<R>
An iterator over the produced values.