Hyperlinkv0.8.0-beta.28

Stream

Stream.accumulateconsteffect/Stream.ts:9200
<A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyArray<A>, E, R>

Accumulates elements into a growing array, emitting the cumulative array for each input chunk.

Example (Accumulating stream elements)

import { Console, Effect, Stream } from "effect"

const program = Effect.gen(function*() {
  const accumulated = yield* Stream.runCollect(
    Stream.fromArray([1, 2, 3]).pipe(
      Stream.rechunk(1),
      Stream.accumulate
    )
  )
  yield* Console.log(accumulated)
})

Effect.runPromise(program)
//=> { _id: 'Chunk', values: [ [ 1 ], [ 1, 2 ], [ 1, 2, 3 ] ] }
Accumulation
Source effect/Stream.ts:92005 lines
export const accumulate = <A, E, R>(self: Stream<A, E, R>): Stream<Arr.NonEmptyArray<A>, E, R> =>
  mapAccumArray(self, Arr.empty<A>, (acc, as) => {
    const combined = Arr.appendAll(acc, as)
    return [combined, [combined]]
  })