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:33

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

When the source stream emits a value, this operator emits a tuple containing that source value along with the most recent values from each auxiliary input.

Type Parameters

T

T = any

The type of values emitted by the source stream.

R

R extends readonly unknown[] = any[]

A readonly array/tuple representing the types emitted by the auxiliary streams.

Parameters

args

...any[]

One or more streams, promises, or an array of streams/promises whose latest values will be combined with the source value.

Returns

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

A push operator function that transforms the source stream into a stream of combined tuples.

Example

ts
const clicks = fromEvent(document, 'click');
const mouseMoves = fromEvent(document, 'mousemove');

clicks.pipe(withLatestFrom(mouseMoves)).subscribe({
next: ([clickEvent, lastMouseMove]) => {
console.log('Clicked at:', lastMouseMove.clientX, lastMouseMove.clientY);
}
});

Released under the GNU AGPL v3 or later.