Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / withLatestFrom

Function: withLatestFrom()

withLatestFrom<T, R>(...args): Operator<T, [T, ...R[]]>

Defined in: projects/libraries/streamix/src/lib/operators/withLatestFrom.ts:31

Combines the source stream with the latest values from one or more auxiliary streams or promises.

When the source stream emits a value, emits a tuple containing the source value and the most recent values from each auxiliary stream or promise. No value is emitted until all auxiliary streams have emitted at least once.

If any auxiliary stream or promise errors, the output stream errors. If the source completes, the output completes.

Type Parameters

T

T = any

The type of values emitted by the source stream.

R

R extends readonly unknown[] = any[]

The tuple of types emitted by the auxiliary streams.

Parameters

args

...(Stream<T> | Promise<T>)[]

One or more streams or promises whose latest values will be combined with the source value.

Returns

Operator<T, [T, ...R[]]>

An operator function that emits a tuple of the source value and the latest values from each auxiliary input.

Example

ts
// Combine clicks with the latest mouse position
clicks.pipe(withLatestFrom(mouseMoves))
// Emits: [clickEvent, latestMousePosition]

Released under the MIT License.