Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
For aggregation behavior with incremental intermediate results, see Rx.Observable.scan
.
[seed]
(Mixed): The initial accumulator value.accumulator
(Function
): accumulator An accumulator function to be invoked on each element.
(Observable
): An observable sequence containing a single element with the final accumulator value.
// Using a seed for the accumulate
var source = Rx.Observable.range(1, 10).aggregate(1, function (acc, x) {
return acc * x;
});
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 3628800
// => Completed
// Without a seed
var source = Rx.Observable.range(1, 10).aggregate(function (acc, x) {
return acc + x;
});
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 55
// => Completed
File:
Dist:
Prerequisites:
NPM Packages:
NuGet Packages:
Unit Tests: