UNPKG

667 BJavaScriptView Raw
1import { identity } from '../util/identity';
2/**
3 * Computes the sum of a sequence of values.
4 *
5 * @export
6 * @param {Iterable<any>} source A sequence of values to calculate the sum.
7 * @param {MathOptions<any>} [options] Optional options for providing a selector, thisArg and abort signal.
8 * @returns {Promise<number>} A promise containing the sum of the sequence of values.
9 */
10export function sum(source, options) {
11 const { ['selector']: selector = identity, ['thisArg']: thisArg } = options || {};
12 let value = 0;
13 for (const item of source) {
14 value += selector.call(thisArg, item);
15 }
16 return value;
17}
18
19//# sourceMappingURL=sum.mjs.map