Function scanSync

  • Reduces an input sync iterable to a sequence of accumulated values using a reducer function.

    Returns

    A function that accepts an input sync iterable and returns an iterable that yields accumulated values.

    Example

    const input = [1, 2, 3];
    const add = (acc: number, value: number) => acc + value;
    const scanSumSync = scanSync(add)(input);

    for (const value of scanSumSync) {
    console.log(value); // Logs 1, 3, 6
    }

    Remarks

    Available as scan when imported from peter-piper/sync.

    Type Parameters

    • T

      The type of elements in the input sync iterable.

    • U = T

      The type of the output value. Defaults to T.

    Parameters

    • reducer: Reducer<T, U>

      A reducer function that takes the accumulator, a value, and its index.

    • Optional initialValue: U

      Optional. The initial value of the accumulator. If not provided, the first value of the iterable is used.

    Returns ((input: Iterable<T>) => Iterable<U>)

      • (input: Iterable<T>): Iterable<U>
      • Parameters

        • input: Iterable<T>

        Returns Iterable<U>

Generated using TypeDoc