zip

Combines multiple Observables to create an Observable whose values are calculated from the values, in order, of each of its input Observables.

zip<O extends ObservableInput<any>, R>(...observables: Array<O | ((...values: ObservedValueOf<O>[]) => R)>): Observable<ObservedValueOf<O>[] | R>

Parameters

observables

Type: Array[]) => R)>.

Returns

Observable<ObservedValueOf<O>[] | R>:

Description

If the last parameter is a function, this function is used to compute the created value from the input values. Otherwise, an array of the input values is returned.

Example

Combine age and name from different sources

import { zip, of } from 'rxjs'; import { map } from 'rxjs/operators'; let age$ = of<number>(27, 25, 29); let name$ = of<string>('Foo', 'Bar', 'Beer'); let isDev$ = of<boolean>(true, true, false); zip(age$, name$, isDev$).pipe( map(([age, name, isDev]) => ({ age, name, isDev })), ) .subscribe(x => console.log(x)); // outputs // { age: 27, name: 'Foo', isDev: true } // { age: 25, name: 'Bar', isDev: true } // { age: 29, name: 'Beer', isDev: false }

Overloads

zip(v1: O1, resultSelector: (v1: ObservedValueOf<O1>) => R): Observable<R>

Parameters

v1

Type: O1.

resultSelector

Type: (v1: ObservedValueOf) => R.

Returns

Observable<R>

zip(v1: O1, v2: O2, resultSelector: (v1: ObservedValueOf<O1>, v2: ObservedValueOf<O2>) => R): Observable<R>

Parameters

v1

Type: O1.

v2

Type: O2.

resultSelector

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

Returns

Observable<R>

zip(v1: O1, v2: O2, v3: O3, resultSelector: (v1: ObservedValueOf<O1>, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>) => R): Observable<R>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

resultSelector

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

Returns

Observable<R>

zip(v1: O1, v2: O2, v3: O3, v4: O4, resultSelector: (v1: ObservedValueOf<O1>, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>, v4: ObservedValueOf<O4>) => R): Observable<R>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

resultSelector

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

Returns

Observable<R>

zip(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, resultSelector: (v1: ObservedValueOf<O1>, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>, v4: ObservedValueOf<O4>, v5: ObservedValueOf<O5>) => R): Observable<R>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

resultSelector

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

Returns

Observable<R>

zip(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, resultSelector: (v1: ObservedValueOf<O1>, v2: ObservedValueOf<O2>, v3: ObservedValueOf<O3>, v4: ObservedValueOf<O4>, v5: ObservedValueOf<O5>, v6: ObservedValueOf<O6>) => R): Observable<R>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

v6

Type: O6.

resultSelector

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

Returns

Observable<R>

zip(v1: O1, v2: O2): Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>]>

Parameters

v1

Type: O1.

v2

Type: O2.

Returns

Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>]>

zip(v1: O1, v2: O2, v3: O3): Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>]>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

Returns

Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>]>

zip(v1: O1, v2: O2, v3: O3, v4: O4): Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>]>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

Returns

Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>]>

zip(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5): Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>]>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

Returns

Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>]>

zip(v1: O1, v2: O2, v3: O3, v4: O4, v5: O5, v6: O6): Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>, ObservedValueOf<O6>]>

Parameters

v1

Type: O1.

v2

Type: O2.

v3

Type: O3.

v4

Type: O4.

v5

Type: O5.

v6

Type: O6.

Returns

Observable<[ObservedValueOf<O1>, ObservedValueOf<O2>, ObservedValueOf<O3>, ObservedValueOf<O4>, ObservedValueOf<O5>, ObservedValueOf<O6>]>

zip(array: O[]): Observable<ObservedValueOf<O>[]>

Parameters

array

Type: O[].

Returns

Observable<ObservedValueOf<O>[]>

zip(array: ObservableInput<any>[]): Observable<R>

Parameters

array

Type: ObservableInput[].

Returns

Observable<R>

zip(array: O[], resultSelector: (...values: ObservedValueOf<O>[]) => R): Observable<R>

Parameters

array

Type: O[].

resultSelector

Type: (...values: ObservedValueOf[]) => R.

Returns

Observable<R>

zip(array: ObservableInput<any>[], resultSelector: (...values: any[]) => R): Observable<R>

Parameters

array

Type: ObservableInput[].

resultSelector

Type: (...values: any[]) => R.

Returns

Observable<R>

zip(...observables: O[]): Observable<ObservedValueOf<O>[]>

Parameters

observables

Type: O[].

Returns

Observable<ObservedValueOf<O>[]>

zip(...observables: Array<O | ((...values: ObservedValueOf<O>[]) => R)>): Observable<R>

Parameters

observables

Type: Array[]) => R)>.

Returns

Observable<R>

zip(...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): Observable<R>

Parameters

observables

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

Returns

Observable<R>