Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass array of observables to zip

I have an array of observables and want to pass to Rx.Observable.zip. I tried and it does not get subscribed at all.

Code snippet(just am example):

const sourceOne = Rx.Observable.of('Hello');
const sourceTwo = Rx.Observable.of('World!');
const sourceThree = Rx.Observable.of('Goodbye');
const sourceFour = Rx.Observable.of('World!');
const arr$ = [sourceOne, sourceTwo, sourceThree, sourceFour];

const zip$ = (a$) => Rx.Observable.zip(a$);

const subscribe = zip$(arr$).subscribe(val => console.log(val));

Is there a way to pass an array to Rx.Observable.zip?

like image 486
softshipper Avatar asked Jan 13 '17 09:01

softshipper


1 Answers

Operator zip accepts only an unpacked array.

zip(sourceOne, sourceTwo, sourceThree, ...);

If you're using ES6 you can also use destructuring assignment with ...:

const zip$ = (a$) => zip(...arr$);

See live demo: https://jsbin.com/tinaxeq/1/edit?js,console

like image 115
martin Avatar answered Oct 20 '22 20:10

martin