I have this chain which should be concatenating 10 Observables into 1 Observable, where each of the 10 Observables should basically just be unwrapped to an integer:
const Rx = require('rxjs');
var i = 0;
const obs = Rx.Observable.interval(10)
.map(() => i++)
.map(val => Rx.Observable.create(obs => {
obs.next(val)
}))
.take(10)
.reduce((prev, curr) => {
return prev.concat(curr); // concat all observables
})
.last(val => val.flatMap(inner => inner));
// subscribe to Observable
obs.subscribe(v => {
console.log('\n next (and only) result => \n', v);
});
What's happening is that all 10 Observables should be concatenated together, but I cannot extract the values from those 10 Observables (which have become 1 Observable). So my question is, how can I unwrap that final observable and extract the value?
Anyone know what I am talking about?
Instead of reduce + last, you can use concatAll (or concatMap) to concatenate inner sequences and preserve order:
edit:
takeLast(1)instead offinalValue()