@reactivex/ix-es5-esm
Version:
The Interactive Extensions for JavaScript
31 lines (29 loc) • 1.13 kB
JavaScript
import { __values } from "tslib";
import { identity } from '../util/identity.js';
/**
* Computes the sum of a sequence of values.
*
* @param {Iterable<any>} source A sequence of values to calculate the sum.
* @param {MathOptions<any>} [options] Optional options for providing a selector, thisArg and abort signal.
* @returns {Promise<number>} A promise containing the sum of the sequence of values.
*/
export function sum(source, options) {
var e_1, _a;
var _b = options || {}, _c = _b["selector"], selector = _c === void 0 ? identity : _c, thisArg = _b["thisArg"];
var value = 0;
try {
for (var source_1 = __values(source), source_1_1 = source_1.next(); !source_1_1.done; source_1_1 = source_1.next()) {
var item = source_1_1.value;
value += selector.call(thisArg, item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (source_1_1 && !source_1_1.done && (_a = source_1.return)) _a.call(source_1);
}
finally { if (e_1) throw e_1.error; }
}
return value;
}
//# sourceMappingURL=sum.js.map