effect-io-ai

Package: effect
Module: Stream

Stream.collect

Collects all elements into an array and emits it as a single element.

Example (Collecting values into a stream element)

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

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

const program = Effect.gen(function*() {
  const collected = yield* stream.pipe(Stream.collect, Stream.runCollect)
  yield* Console.log(collected[0])
})

Effect.runPromise(program)
// [1, 2, 3]

Signature

declare const collect: <A, E, R>(self: Stream<A, E, R>) => Stream<Array<A>, E, R>

Source

Since v4.0.0