# scan

Scans the stream with a pure function, emitting the accumulated state after each element.
Emits the initial value first, then for each input `a` emits `f(state, a)` and updates state.

Semantics align with Effect Stream's `scan`: output is `initial`, `f(initial, a1)`, `f(..., a2)`, ...

## Signatures

```ts
export declare const scan: {
    <S, A>(initial: S, f: (s: S, a: A) => S): <E, R>(fx: Fx<A, E, R>) => Fx<S, E, R>;
    <A, E, R, S>(fx: Fx<A, E, R>, initial: S, f: (s: S, a: A) => S): Fx<S, E, R>;
};
```

## Why

`scan` exposes every accumulated state, including `initial` before the source is run. For `n`
inputs it emits `n + 1` states in order, making incremental reduction observable.

## Ownership and lifetime

Each run owns an independent accumulator and releases it when the run ends. The pure reducer
acquires no resources and preserves source failures, services, and interruption.

## Examples

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

const totals = Fx.fromIterable([1, 2, 3]).pipe(Fx.scan(0, (sum, n) => sum + n))
```
