# scanEffect

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

## Signatures

```ts
export declare const scanEffect: {
    <S, A, E2, R2>(initial: S, f: (s: S, a: A) => Effect.Effect<S, E2, R2>): <E, R>(fx: Fx<A, E, R>) => Fx<S, E | E2, R | R2>;
    <A, E, R, S, E2, R2>(fx: Fx<A, E, R>, initial: S, f: (s: S, a: A) => Effect.Effect<S, E2, R2>): Fx<S, E | E2, R | R2>;
};
```

## Why

`scanEffect` permits a failing or service-backed accumulated transition and emits `initial`
before subscribing. It does not serialize later producer callbacks: overlapping reductions can
read the same state, finish out of order, and overwrite one another's next state.

## Ownership and lifetime

One mutable accumulator is owned per run. Reducer Effects inherit producer concurrency and use
the captured services. Failure is delivered to the Sink without committing that transition;
interruption follows the invoking callback rather than locking the entire run.

## Examples

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

const concurrent = Fx.make<number>((sink) =>
  Effect.all([sink.onSuccess(1), sink.onSuccess(2)], { concurrency: "unbounded", discard: true })
)
const program = Fx.collectAll(concurrent.pipe(Fx.scanEffect(0, (sum, n) => Effect.succeed(sum + n))))
// Both overlapping reductions may observe sum === 0; serialize the producer for atomic totals.
```
