function / @typed/fx/Sink

head

Keeps only the first value. Pass a Ref<Option.Option<A>> (e.g. Ref.make(Option.none())); after running, read the result with Ref.get(ref).

Package version
2.0.0-beta.13
Category
Collecting values
Since
1.0.0

Import

import { head } from "@typed/fx/Sink";

Signatures

export declare function head<A, E>(ref: Ref.Ref<Option.Option<A>>): Sink<A, E, never>;

Why

The first observed value can be retained in a caller-owned location without stopping the producer.

Ownership and lifetime

The caller owns the Ref. Each success returns a lazy atomic update. The first update Effect to execute while the Ref is None stores its value; that is the first callback only when the producer executes callback Effects serially. Later updates leave Some unchanged. Failures are ignored.

Examples

import { Effect, Option, Ref } from "effect"
import * as Sink from "@typed/fx/Sink"
const program = Effect.gen(function* () {
  const first = yield* Ref.make<Option.Option<number>>(Option.none())
  return Sink.head(first)
})

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source