Hyperlinkv0.8.0-beta.28

Stream

Stream.runCollectconsteffect/Stream.ts:10618
<A, E, R>(self: Stream<A, E, R>): Effect.Effect<Array<A>, E, R>

Runs the stream and collects all elements into an array.

Example (Collecting stream values)

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

const stream = Stream.make(1, 2, 3, 4, 5)

const program = Effect.gen(function*() {
  const collected = yield* Stream.runCollect(stream)
  yield* Console.log(collected)
})

Effect.runPromise(program)
// [1, 2, 3, 4, 5]
destructors
Source effect/Stream.ts:1061811 lines
export const runCollect = <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Array<A>, E, R> =>
  Channel.runFold(
    self.channel,
    () => [] as Array<A>,
    (acc, chunk) => {
      for (let i = 0; i < chunk.length; i++) {
        acc.push(chunk[i])
      }
      return acc
    }
  )
Referenced by 1 symbols