# loop

Threads pure state through successful inputs and forwards one derived value per input.

## Signatures

```ts
export declare const loop: {
    <B, A, C>(seed: B, f: (acc: B, a: A) => readonly [
        C,
        B
    ]): <E, R>(sink: Sink<C, E, R>) => Sink<A, E, R>;
    <A, E, R, B, C>(sink: Sink<C, E, R>, seed: B, f: (acc: B, a: A) => readonly [
        C,
        B
    ]): Sink<A, E, R>;
};
```

## Why

`loop` implements an ordered consumer-side state machine without exposing mutable state to the
producer.

## Ownership and lifetime

Each adapted sink owns its seed. Updates are synchronous and follow callback invocation order;
every input produces exactly one downstream success. Failures bypass the state machine. Reusing
the same sink for another producer run continues from its retained seed; create a new sink to reset.

## Examples

```ts
import { Effect } from "effect"
import * as Sink from "@typed/fx/Sink"
const totals = Sink.loop(Sink.make(Effect.logError, Effect.log), 0, (sum, n: number) => [sum + n, sum + n])
```
