Prelude API
    Preparing search index...
    • Creates a consumer that reduces values from an async iterable to a single result.

      Type Parameters

      • T
      • R

      Parameters

      • reduction: (result: R, value: T, index: number) => R | Promise<R>

        Function that takes the accumulated result, the current value, and the index, and returns the new accumulated result

      • initial: R | Promise<R>

        The initial value for the reduction

      Returns (values: AsyncIterable<T>) => Promise<R>

      A consumer function that returns a promise resolving to the final reduced value

      Processes each value in the async iterable using the provided reduction function, accumulating a result starting with the initial value.

      const sum = await G.pipe(
      G.ofIterable([1, 2, 3, 4, 5]),
      G.reduce((acc, value) => acc + value, 0)
      ); // sum === 15