variable / @typed/fx

RefSubject.scan

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

Fx subscriptions follow Fx.scan semantics (emit initial, then fold each source value). Effect sampling accumulates across source versions via a private state ref (do not mix heavy subscribe + sample on the same scan if you need a single shared accumulator).

Package version
2.0.0-beta.13
Category
Accumulation
Since
1.0.0
Member of
RefSubject

Import

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

Access RefSubject.scan through the imported RefSubject export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

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

Why

Stateful scan over a RefSubject / Computed, producing a Computed of the accumulated state. Fx subscriptions follow Fx.scan semantics (emit initial, then fold each source value). Effect sampling accumulates across source versions via a private state ref (do not mix heavy subscribe + sample on the same scan if you need a single shared accumulator). 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, advanced after a successful fold for a new source version. The pushed channel runs Fx.scanEffect from initial inside Subject.hold: observers using the same Context share that active scan and retained result. The last observer ends its session and clears its held value. The observing Scope owns subscription 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