Hyperlinkv0.8.0-beta.28

Channel

Channel.runCountconsteffect/Channel.ts:7692
<OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
): Effect.Effect<void, OutErr, Env>

Runs a channel and counts the number of elements it outputs.

Example (Counting channel output)

import { Channel, Data } from "effect"

class CountError extends Data.TaggedError("CountError")<{
  readonly reason: string
}> {}

// Create a channel with multiple elements
const numbersChannel = Channel.fromIterable([1, 2, 3, 4, 5])

// Count the elements
const countEffect = Channel.runCount(numbersChannel)

// Effect.runSync(countEffect) // Returns: 5
execution
export const runCount = <OutElem, OutErr, OutDone, Env>(
  self: Channel<OutElem, OutErr, OutDone, unknown, unknown, unknown, Env>
): Effect.Effect<void, OutErr, Env> => runFold(self, () => 0, (acc) => acc + 1)