I am using RxJS here and I do not seem to overcome this seemingly simple problem.
rx.Observable .from([1,2,3,54,3,22,323,23,11,2]) .distinct() .subscribe(function next (x) { console.log('Next'); console.log(x); }, function error (x) { console.log('Error'); console.log(x); }, function completed () { console.log('Completed'); });
The code above splashes out each element of the array in the order as expected.
rx.Observable .fromPromise(getNumbers([1,2,3,54,3,22,323,23,11,2])) .distinct() .subscribe(function next (x) { console.log('Next'); console.log(x); }, function error (x) { console.log('Error'); console.log(x); }, function completed () { console.log('Completed'); }); function getNumbers (nums) { return new Promise(function (resolve, reject) { resolve(nums); }); }
Here, although I only get the full array (ie [ 1, 2, 3, 54, 3, 22, 323, 23, 11, 2 ] ). Doesn't RxJS break the result? I hope he at least had some kind of logic for this.
thanks
arrays reactive-programming rxjs
Matt rea
source share