Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 2.67 KB

aggregate.md

File metadata and controls

76 lines (60 loc) · 2.67 KB

Rx.Observable.prototype.aggregate([seed], accumulator)

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.

Arguments

  1. [seed] (Mixed): The initial accumulator value.
  2. accumulator (Function): accumulator An accumulator function to be invoked on each element.

Returns

(Observable): An observable sequence containing a single element with the final accumulator value.

Example

// 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     

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: