This is RxJS v 4. Find the latest version here
Concatenates the observable sequences or Promises obtained by running the specified result selector for each element in source.
There is an alias for this method called forIn
for browsers <IE9
-
sources
(Array): An array of values to turn into an observable sequence. -
resultSelector
(Function
): A function to apply to each item in the sources array to turn it into an observable sequence. The resultSelector is called with the following information:- the value of the element
- the index of the element
- the Observable object being subscribed
-
[thisArg]
(Any
): Object to use asthis
when executingresultSelector
.
(Observable
): An observable sequence from the concatenated observable sequences or Promises.
/* Using Observables */
var array = [1, 2, 3];
var source = Rx.Observable.for(
array,
function (x) {
return Rx.Observable.return(x);
});
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 1
// => Next: 2
// => Next: 3
// => Completed
/* Using Promises */
var array = [1, 2, 3];
var source = Rx.Observable.for(
array,
function (x) {
return RSVP.Promise.resolve(x);
});
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 1
// => Next: 2
// => Next: 3
// => Completed
File:
Dist:
Prerequisites:
- If using
rx.experimental.js
NPM Packages:
NuGet Packages:
Unit Tests: