Hyperlinkv0.8.0-beta.28

Stream

Stream.runCountconsteffect/Stream.ts:10652
<A, E, R>(self: Stream<A, E, R>): Effect.Effect<number, E, R>

Runs the stream and returns the number of elements emitted.

Example (Counting stream values)

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

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

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

Effect.runPromise(program)
// 5
destructors
export const runCount = <A, E, R>(self: Stream<A, E, R>): Effect.Effect<number, E, R> =>
  Channel.runFold(self.channel, () => 0, (acc, chunk) => acc + chunk.length)