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

    Function scan

    • Accumulates the sequence and emits each intermediate result.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • accumulator: Accumulator<TElement, TElement>

        Function that merges the current accumulator value with the next element to produce the subsequent accumulator.

      Returns IEnumerable<TElement>

      A deferred sequence containing every intermediate accumulator produced by accumulator.

      Thrown when source is empty and seed is not provided.

      source is enumerated exactly once. Supplying seed prevents exceptions on empty sources but the seed itself is not emitted.

      const numbers = [1, 2, 3, 4, 5];
      const runningTotal = scan(numbers, (acc, x) => acc + x).toArray();
      console.log(runningTotal); // [1, 3, 6, 10, 15]
    • Accumulates the sequence and emits each intermediate result.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      • TAccumulate

        Accumulator type produced by accumulator; defaults to TElement when seed is omitted.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • accumulator: Accumulator<TElement, TAccumulate>

        Function that merges the current accumulator value with the next element to produce the subsequent accumulator.

      • seed: TAccumulate

        Optional initial accumulator. When omitted, the first element supplies the initial accumulator and is emitted as the first result.

      Returns IEnumerable<TAccumulate>

      A deferred sequence containing every intermediate accumulator produced by accumulator.

      Thrown when source is empty and seed is not provided.

      source is enumerated exactly once. Supplying seed prevents exceptions on empty sources but the seed itself is not emitted.

      const numbers = [1, 2, 3, 4, 5];
      const runningTotal = scan(numbers, (acc, x) => acc + x).toArray();
      console.log(runningTotal); // [1, 3, 6, 10, 15]