# loopEffect

Threads state through an effectful success transformation and forwards one value on success.

## Signatures

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

## Why

Stateful consumer transitions can consult Effect services or fail without moving the state
machine into the producer.

## Ownership and lifetime

Callback invocation constructs a transition Effect from the seed visible at that moment. The
adapter does not serialize those Effects: overlapping callbacks can read the same seed, and
successful transitions commit in completion order. A failure is sent to the wrapped sink and does
not commit. The sink instance retains its last committed seed when reused by another producer run;
construct a new adapted sink to reset it. Transition services and interruption remain typed.

## Examples

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