Web streams utils - v0.3.0
    Preparing search index...

    Function scan

    • Create a TransformStream that produces a stream of accumulated values

      Type Parameters

      • T
      • R

      Parameters

      • scanner: (accumulator: R, chunk: T) => SyncOrAsync<R>

        The scanner function to apply to each chunk

      • initialValue: R

        The initial value for the scan

      Returns TransformStream<T, R>

      A TransformStream that emits each intermediate accumulated value

      // Calculate running sum
      const stream = readable.pipeThrough(scan((acc, x) => acc + x, 0));
      // If readable emits [1, 2, 3], the result will be [1, 3, 6]