Function flatMap

  • Remaps and then flattens an iterable, similar to Array.flatMap, except it flattens all iterable values, including strings.

    import {pipe, flatMap} from 'iter-ops';

    const i = pipe(
    ['hello', 'world!'],
    flatMap(a => a.length)
    );

    console.log(...i); //=> 5 6

    Note that when handling a synchronous iterable, this operator can remap+flatten only synchronous sub-iterables. But when handling an asynchronous iterable, it can remap+flatten mixed sub-iterables, i.e. any combination of synchronous and asynchronous sub-iterables.

    Type Parameters

    • T
    • R

    Parameters

    • cb: ((value: T, index: number, state: IterationState) => R | Promise<R>)
        • (value, index, state): R | Promise<R>
        • Parameters

          Returns R | Promise<R>

    Returns Operation<T, R extends UnknownIterable<infer E>
        ? E
        : R>