yta
    Preparing search index...

    Function reduce

    • Consume an async iterator resulting in a single promise.

      import { asAsync, pipe } from "yta";
      import { reduce } from "yta/async";
      import { range } from "yta/sync";

      await pipe(
      range(10),
      asAsync(),
      reduce((sum, x) => sum + x, 0),
      );
      // => 45

      Type Parameters

      • A

        The input type

      • B

        The output value type

      Parameters

      • fn: (acc: B, item: A) => B

        The consuming function

      • init: B

        The initial value

      Returns (items: AsyncIterable<A>) => Promise<B>