variable / @typed/fx/RefSubject

scanEffect

Effectful stateful scan over a RefSubject / Computed, producing a Computed of the accumulated state.

Package version
2.0.0-beta.13
Category
Accumulation
Since
1.0.0

Import

import { scanEffect } from "@typed/fx/RefSubject";

Signatures

export declare const scanEffect: {
    <S, A, E3, R3>(initial: S, f: (s: S, a: A) => Effect.Effect<S, E3, R3>): <E, R>(ref: RefSubject<A, E, R> | Computed<A, E, R>) => Computed<S, E | E3, R | R3>;
    <A, E, R, S, E3, R3>(ref: RefSubject<A, E, R> | Computed<A, E, R>, initial: S, f: (s: S, a: A) => Effect.Effect<S, E3, R3>): Computed<S, E | E3, R | R3>;
    <R0, E0, A, E, R, E2, R2, S, E3, R3>(versioned: Versioned.Versioned<R0, E0, A, E, R, A, E2, R2>, initial: S, f: (s: S, a: A) => Effect.Effect<S, E3, R3>): Computed<S, E0 | E | E2 | E3, R0 | R2 | R3 | Exclude<R, Scope.Scope>>;
};

Why

Effectful stateful scan over a RefSubject / Computed, producing a Computed of the accumulated state. The result remains a lazy view rather than a duplicated mutable value.

Ownership and lifetime

Each Effect Context object gets a private current-read accumulator. It advances only after f succeeds, so a typed failure leaves the previous state intact. The pushed channel runs Fx.scanEffect from initial inside Subject.hold: observers using the same Context share that active scan and retained result; each fold requires R3. The last observer ends its session and clears its held value. The observing Scope owns cleanup. Read accumulators are weakly held by Context and need no finalizer.

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source