interface / @typed/fx

Sink.Sink.WithState

An early-exit sink with a mutable Effect Ref for consumer-local state.

Package version
2.0.0-beta.7
Category
Stateful delivery
Since
1.0.0
Member of
Sink.Sink

Import

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

Access Sink.Sink.WithState through the imported Sink export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

interface WithState<A, E, R, B> extends WithEarlyExit<A, E, R> {
    readonly state: Ref<B>;
}

Why

Stateful consumers can accumulate values without moving that state into the producer.

Ownership and lifetime

The surrounding withState invocation creates and owns the Ref. It remains reachable only for that invocation; callback ordering determines the order of state updates.

Property: state

Mutable state created for the current consumer invocation.

Property: state: Why

Stateful callback logic can use Effect’s atomic Ref operations directly.

Property: state: Ownership and lifetime

withState creates this Ref for one execution; it is not shared with later executions.

Examples

import { Ref } from "effect"
import type * as Sink from "@typed/fx/Sink"
const increment = (sink: Sink.Sink.WithState<number, never, never, number>) =>
  Ref.update(sink.state, (n) => n + 1)

Other public imports

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

Source