Henrik
Henrik

Reputation: 9955

RxJS bind Observable

I'm having trouble with binding the result of observable A to a stream-observable B, such that:

Rx.Observable.concat(
  A,
  A.bind(valuesInA =>
    B.scan((acc, value) => {
      acc.push(value);
      return acc;
    }, valuesInA)))

So for example, if this is the case:

A: { onNext:[monkey], onComplete }
B: { onNext:banana, onNext:tree, onNext: ... }

I would like to get the observable:

AB: { onNext:[monkey],
      onNext:[monkey, banana],
      onNext:[monkey,banana,tree],
      onNext: ... }

If there was a bind operator, and it called its callback when its callee was done, that would be great, because A finishes rather quickly (initial load of values) and then B streams the rest of them.

How do I compose this?


Notes: B.scan( ... ) : Observable<Array<apeness>> so I need to subscribe its result

Upvotes: 1

Views: 1319

Answers (1)

Brandon
Brandon

Reputation: 39222

Flatmap, scan, and startWith:

A.flatMap(a => B.scan((acc,v) => acc.concat(v), a).startWith(a))
 .subscribe(...);

Upvotes: 1

Related Questions