Function reduceSync

  • Reduces an input sync iterable to a single value using a reducer function.

    Returns

    A function that accepts an input sync iterable and returns the reduced value.

    Example

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

    console.log(sumSync); // Logs 6

    Remarks

    Available as reduce 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>) => U)

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

        • input: Iterable<T>

        Returns U

Generated using TypeDoc