withLatestFrom

Combines the source Observable with other Observables to create an Observable whose values are calculated from the latest values of each, only when the source emits.

withLatestFrom<T, R>(...args: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): OperatorFunction<T, R>

Parameters

args

Type: Array | ((...values: Array) => R)>.

Returns

OperatorFunction<T, R>: An Observable of projected values from the most recent values from each input Observable, or an array of the most recent values from each input Observable.

Description

Whenever the source Observable emits a value, it computes a formula using that value plus the latest values from other input Observables, then emits the output of that formula.

withLatestFrom combines each value from the source Observable (the instance) with the latest values from the other input Observables only when the source emits a value, optionally using a project function to determine the value to be emitted on the output Observable. All input Observables must emit at least one value before the output Observable will emit a value.

Example

On every click event, emit an array with the latest timer event plus the click event

import { fromEvent, interval } from 'rxjs'; import { withLatestFrom } from 'rxjs/operators'; const clicks = fromEvent(document, 'click'); const timer = interval(1000); const result = clicks.pipe(withLatestFrom(timer)); result.subscribe(x => console.log(x));

Overloads

withLatestFrom(project: (v1: T) => R): OperatorFunction<T, R>

Parameters

project

Type: (v1: T) => R.

Returns

OperatorFunction<T, R>

withLatestFrom(source2: O2, project: (v1: T, v2: ObservedValueOf<O2>) => R): OperatorFunction<T, R>

Parameters

source2

Type: O2.

project

Type: (v1: T, v2: ObservedValueOf) => R.

Returns

OperatorFunction<T, R>

withLatestFrom(v2: O2, v3: O3, project: (v1: T, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>) => R): OperatorFunction<T, R>

Parameters

v2

Type: O2.

v3

Type: O3.

project

Type: (v1: T, v2: ObservedValueOf, v3: ObservedValueOf) => R.

Returns

OperatorFunction<T, R>

withLatestFrom(v2: O2, v3: O3, v4: O4, project: (v1: T, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>, v4: ObservedValueOf<O4>) => R): OperatorFunction<T, R>

Parameters

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

project

Type: (v1: T, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf) => R.

Returns

OperatorFunction<T, R>

withLatestFrom(v2: O2, v3: O3, v4: O4, v5: O5, project: (v1: T, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>, v4: ObservedValueOf<O4>, v5: ObservedValueOf<O5>) => R): OperatorFunction<T, R>

Parameters

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

project

Type: (v1: T, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf, v5: ObservedValueOf) => R.

Returns

OperatorFunction<T, R>

withLatestFrom(v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, project: (v1: T, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>, v4: ObservedValueOf<O4>, v5: ObservedValueOf<O5>, v6: ObservedValueOf<O6>) => R): OperatorFunction<T, R>

Parameters

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

v6

Type: O6.

project

Type: (v1: T, v2: ObservedValueOf, v3: ObservedValueOf, v4: ObservedValueOf, v5: ObservedValueOf, v6: ObservedValueOf) => R.

Returns

OperatorFunction<T, R>

withLatestFrom(source2: O2): OperatorFunction<T, [T, ObservedValueOf<O2>]>

Parameters

source2

Type: O2.

Returns

OperatorFunction<T, [T, ObservedValueOf<O2>]>

withLatestFrom(v2: O2, v3: O3): OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>]>

Parameters

v2

Type: O2.

v3

Type: O3.

Returns

OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>]>

withLatestFrom(v2: O2, v3: O3, v4: O4): OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>]>

Parameters

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

Returns

OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>]>

withLatestFrom(v2: O2, v3: O3, v4: O4, v5: O5): OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>]>

Parameters

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

Returns

OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>]>

withLatestFrom(v2: O2, v3: O3, v4: O4, v5: O5, v6: O6): OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>, ObservedValueOf<O6>]>

Parameters

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

v6

Type: O6.

Returns

OperatorFunction<T, [T, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>, ObservedValueOf<O6>]>

withLatestFrom(...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): OperatorFunction<T, R>

Parameters

observables

Type: Array | ((...values: Array) => R)>.

Returns

OperatorFunction<T, R>

withLatestFrom(array: ObservableInput<any>[]): OperatorFunction<T, R>

Parameters

array

Type: ObservableInput[].

Returns

OperatorFunction<T, R>

withLatestFrom(array: ObservableInput<any>[], project: (...values: Array<any>) => R): OperatorFunction<T, R>

Parameters

array

Type: ObservableInput[].

project

Type: (...values: Array) => R.

Returns

OperatorFunction<T, R>

See Also