Skip to content

@continuum-js/frp


@continuum-js/frp / Stream

Class: Stream<A>

Defined in: index.ts:410

Discrete occurrences over time (push). Denotationally [(Time, A)]: at most one occurrence per moment — simultaneous inputs coalesce (see merge).

Extended by

Type Parameters

A

A

Constructors

Constructor

new Stream<A>(rank?): Stream<A>

Defined in: index.ts:456

Parameters

rank?

number = 0

Returns

Stream<A>

Properties

onSleep

onSleep: (() => void) | null = null

Defined in: index.ts:447

Internal

Extra teardown run on sleep/dispose (flatten's inner subscription).


onWake

onWake: (() => void) | null = null

Defined in: index.ts:445

Internal

Reseed hook run on wake, before inputs attach (lift caches).


rank

rank: number

Defined in: index.ts:412

Internal

Topological height in the graph (propagation order).

Accessors

disposed

Get Signature

get disposed(): boolean

Defined in: index.ts:452

True once dispose() has run.

Returns

boolean

Methods

accum()

accum<B>(init, f): State<B>

Defined in: index.ts:820

Fold occurrences into a behavior. Fused: one node and one edge instead of the accumE + hold pair — every counter in every app pays half.

Type Parameters

B

B

Parameters

init

B

f

(a, acc) => B

Returns

State<B>


accumE()

accumE<B>(init, f): Stream<B>

Defined in: index.ts:789

Fold occurrences into a stream of accumulated states. State — the fold process belongs to the ambient scope (see hold).

Type Parameters

B

B

Parameters

init

B

f

(a, acc) => B

Returns

Stream<B>


attach_()

attach_(target, h): Edge<any>

Defined in: index.ts:536

Internal

Closure-free subscription: returns the edge record. The handler kind must match the target (Observer for POST, Handler else) — see the Edge discriminant.

Parameters

target

Stream<any> | null

h

Handler<A> | Observer<A>

Returns

Edge<any>


consume()

consume<X>(input, h): void

Defined in: index.ts:696

Internal

Subscribe to input and register the teardown for dispose().

Type Parameters

X

X

Parameters

input

Stream<X>

h

Handler<X>

Returns

void


dispose()

dispose(): void

Defined in: index.ts:710

Detach this node from its inputs (breaking the push chain so it can be collected) and drop its downstream links. Idempotent. Cascades upstream through derived intermediates that become unused, but never to sources.

Returns

void


ensureBiggerThan()

ensureBiggerThan(limit): void

Defined in: index.ts:472

Internal

Raise this node's rank above limit and propagate the bump downstream, so a node never has a rank ≤ one of its inputs. Detects dependency cycles.

Iterative on an explicit stack: a bump cascades through the entire downstream chain, and a deep chain must not overflow the call stack. onPath mirrors the recursion's path-tracking: a node met twice on ONE dfs path is a cycle; met again on a sibling path (a diamond) it is either already high enough (fast path) or bumped once more — same as the recursive formulation.

Parameters

limit

number

Returns

void


filter()

filter(pred): Stream<A>

Defined in: index.ts:742

Parameters

pred

(a) => boolean

Returns

Stream<A>


hold()

hold(init): State<A>

Defined in: index.ts:756

Step function: hold the last occurrence, committing at the moment boundary. State — so it needs an owner: the process that keeps the value current is registered in the ambient scope and detaches when the scope disposes (the state then answers with its final value).

Parameters

init

A

Returns

State<A>


listen()

listen(h): Unlisten

Defined in: index.ts:929

Observer (phase post): fires after the moment closes, FIFO.

Parameters

h

(a) => void

Returns

Unlisten


listen_()

listen_(target, h): Unlisten

Defined in: index.ts:528

Internal

Register an in-graph subscriber. Returns an unsubscribe handle.

Parameters

target

Stream<any> | null

h

Handler<A>

Returns

Unlisten


map()

map<B>(f): Stream<B>

Defined in: index.ts:732

Type Parameters

B

B

Parameters

f

(a) => B

Returns

Stream<B>


mapTo()

mapTo<B>(b): Stream<B>

Defined in: index.ts:738

Type Parameters

B

B

Parameters

b

B

Returns

Stream<B>


once()

once(): Stream<A>

Defined in: index.ts:850

Only the first occurrence passes. A formula: cold occurrences nobody observed do not spend it; once it fired while warm, the flag persists across sleep (an observed occurrence stays observed).

Returns

Stream<A>


onDispose()

onDispose(fn): void

Defined in: index.ts:701

Internal

Register an extra teardown to run on dispose().

Parameters

fn

() => void

Returns

void


or()

or(other): Stream<A>

Defined in: index.ts:881

Left-biased merge: on simultaneous occurrences the left wins.

Parameters

other

Stream<A>

Returns

Stream<A>


retain()

retain(): this

Defined in: index.ts:942

Performance hint: keep a pure derivation attached across listener churn instead of sleeping and re-waking (useful for a hot shared chain whose listeners come and go). Never required for correctness.

Returns

this


send_()

send_(t, a): void

Defined in: index.ts:594

Internal

Push an occurrence to every current subscriber.

Parameters

t

Transaction

a

A

Returns

void


source()

source<X>(input, h): void

Defined in: index.ts:622

Internal

Register a lazy input (see srcs).

Type Parameters

X

X

Parameters

input

Stream<X>

h

Handler<X>

Returns

void


subscribe()

subscribe<X>(input, h): Unlisten

Defined in: index.ts:691

Internal

Subscribe this node to input (rank-tracked).

Type Parameters

X

X

Parameters

input

Stream<X>

h

Handler<X>

Returns

Unlisten


unlisten_()

unlisten_(rec): void

Defined in: index.ts:574

Internal

O(1) edge removal: clear the inline slot, or swap with the array's last edge and fix its index.

Parameters

rec

Edge<any>

Returns

void


when()

when(b): Stream<A>

Defined in: index.ts:872

Pass occurrences only while the state is true.

Parameters

b

State<boolean>

Returns

Stream<A>


merge()

static merge<A>(ea, eb, combine): Stream<A>

Defined in: index.ts:886

Merge two events; simultaneous occurrences coalesce once via combine.

Type Parameters

A

A

Parameters

ea

Stream<A>

eb

Stream<A>

combine

(l, r) => A

Returns

Stream<A>