Function flatMap

  • Remaps and then flattens an iterable, consistent with the logic of Array.flatMap

    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, index, state) => R | Promise<R>)
        • (value, index, state): R | Promise<R>
        • Parameters

          Returns R | Promise<R>

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

    See