@mirei/ts-collections
    Preparing search index...

    Function aggregate

    • Combines the elements of the sequence by applying an accumulator to each element and optionally projecting the final result.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      Returns TElement

      The final accumulator (or its projection).

      Thrown when source has no elements and no seed is provided.

      The source sequence is enumerated exactly once. Supply a seed to avoid exceptions on empty sequences and to control the accumulator type.

      const numbers = [1, 2, 3, 4, 5];
      const sum = aggregate(numbers, (acc, x) => acc + x);
      console.log(sum); // 15

      const product = aggregate(numbers, (acc, x) => acc * x, 1);
      console.log(product); // 120
    • Combines the elements of the sequence by applying an accumulator to each element and optionally projecting the final result.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      • TAccumulate

        Type of the intermediate accumulator. Defaults to TElement when no seed is provided.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • accumulator: Accumulator<TElement, TAccumulate>

        Function that merges the running accumulator with the next element.

      • seed: TAccumulate

        Optional initial accumulator value. When omitted, the first element is used as the starting accumulator.

      Returns TAccumulate

      The final accumulator (or its projection).

      Thrown when source has no elements and no seed is provided.

      The source sequence is enumerated exactly once. Supply a seed to avoid exceptions on empty sequences and to control the accumulator type.

      const numbers = [1, 2, 3, 4, 5];
      const sum = aggregate(numbers, (acc, x) => acc + x);
      console.log(sum); // 15

      const product = aggregate(numbers, (acc, x) => acc * x, 1);
      console.log(product); // 120
    • Combines the elements of the sequence by applying an accumulator to each element and optionally projecting the final result.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      • TAccumulate

        Type of the intermediate accumulator. Defaults to TElement when no seed is provided.

      • TResult

        Type returned when a resultSelector is supplied.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • accumulator: Accumulator<TElement, TAccumulate>

        Function that merges the running accumulator with the next element.

      • seed: TAccumulate

        Optional initial accumulator value. When omitted, the first element is used as the starting accumulator.

      • resultSelector: Selector<TAccumulate, TResult>

        Optional projection applied to the final accumulator before it is returned.

      Returns TResult

      The final accumulator (or its projection).

      Thrown when source has no elements and no seed is provided.

      The source sequence is enumerated exactly once. Supply a seed to avoid exceptions on empty sequences and to control the accumulator type.

      const numbers = [1, 2, 3, 4, 5];
      const sum = aggregate(numbers, (acc, x) => acc + x);
      console.log(sum); // 15

      const product = aggregate(numbers, (acc, x) => acc * x, 1);
      console.log(product); // 120