# loop

Loops over an Fx with an accumulator, producing a new value for each element
and updating the accumulator.

## Signatures

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

## Why

`loop` is the primitive for a synchronous state machine over pushed values. Every input emits
exactly one output and installs exactly one next state, preserving source order.

## Ownership and lifetime

A fresh accumulator starts from `seed` for each run and is discarded when that run ends. The
pure callback adds no failures, services, fibers, or resources.

## Examples

```ts
import { Fx } from "@typed/fx"

const indexed = Fx.fromIterable(["a", "b"]).pipe(Fx.loop(0, (index, value) => [[index, value] as const, index + 1]))
```
