This is RxJS v 4. Find the latest version here
Projects each element of an observable sequence into a new form by incorporating the element's index. There is an alias for this method called map
.
selector
(Function
|Object
): Transform function to apply to each source element or an element to yield. If selector is a function, it 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 executing the predicate.
(Observable
): An observable sequence which results from the comonadic bind operation.
// Using a value
var md = Rx.Observable.fromEvent(document, 'mousedown').map(true);
var mu = Rx.Observable.fromEvent(document, 'mouseup').map(false);
// Using a function
var source = Rx.Observable.range(1, 3)
.select(function (x, idx, obs) {
return x * x;
});
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 1
// => Next: 4
// => Next: 9
// => Completed
File:
Dist:
NPM Packages:
NuGet Packages:
Unit Tests: