Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.49k stars 2.1k forks source link

.zip does not work properly with Observable[] #1313

Open vekexasia opened 8 years ago

vekexasia commented 8 years ago

Hello all,

the following example shows the problem:

rx.Observable.zip(
  [1, 2, 3].map(item => rx.Observable.of(`maio ${item}`)),
  (...args) => {
    console.log(args);
    return 'ciao'
  })
  .subscribe(n => console.log(n)
  )

no items are emitted and project function is not called either. but zip.d.ts has a signature explicitly allowing such call:

export declare function zipStatic<T, R>(array: ObservableInput<T>[], project: (...values: Array<T>) => R): Observable<R>;
stefanocke commented 7 years ago

I had the same issue. As workaround I used the spread operator to convert from sequence to vararg. Something like:

rx.Observable.zip( ... ([1, 2, 3].map(item => rx.Observable.of(maio ${item}))), (...args) => { console.log(args); return 'ciao' }) .subscribe(n => console.log(n) )

See also http://stackoverflow.com/questions/1316371/converting-an-array-to-a-function-arguments-list