Hyperlinkv0.8.0-beta.28

Stream

Stream.runHeadconsteffect/Stream.ts:10813
<A, E, R>(self: Stream<A, E, R>): Effect.Effect<Option.Option<A>, E, R>

Runs the stream and returns the first element as an Option.

Example (Getting the first stream value)

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

const program = Effect.gen(function*() {
  const head = yield* Stream.runHead(Stream.make(1, 2, 3))
  yield* Console.log(Option.getOrThrow(head))
})

Effect.runPromise(program)
// 1
destructors
export const runHead = <A, E, R>(self: Stream<A, E, R>): Effect.Effect<Option.Option<A>, E, R> =>
  Effect.map(Channel.runHead(self.channel), Option.map(Arr.getUnsafe(0)))