# Sink.Sink.WithState

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

## Signatures

```ts
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

```ts
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)
```
