yta
    Preparing search index...

    Function flatMap

    • Map each item into an iterator and flatten.

      import { pipe } from "yta";
      import { flatMap, toArray } from "yta/async";
      import { range } from "yta/sync";

      await pipe(
      of(0, 1, 2, 3),
      flatMap((n) => of(...range(n))),
      toArray(),
      );
      // => [0, 0, 1, 0, 1, 2]

      See also:

      Type Parameters

      • A

        The input type

      • B

        The output type

      Parameters

      • fn: (item: A) => AsyncIterable<B>

        The mapping function

      Returns (items: AsyncIterable<A>) => AsyncGenerator<B, void>