UNPKG

2.66 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/sum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAyB/C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,MAA0B,EAAE,OAA0B;IAC9E,MAAM,EACJ,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,aAAoB,EAC7C,CAAC,QAAQ,CAAC,EAAE,MAAM,EAClB,CAAC,SAAS,CAAC,EAAE,OAAO,GACrB,GAAG,OAAO,IAAI,EAAE,CAAC;IAClB,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACtD,KAAK,IAAI,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;KACrD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","file":"sum.js","sourcesContent":["import { identityAsync } from '../util/identity';\nimport { wrapWithAbort } from './operators/withabort';\nimport { throwIfAborted } from '../aborterror';\nimport { MathOptions } from './mathoptions';\n\n/**\n * Computes the sum of a sequence of values.\n *\n * @export\n * @param {AsyncIterable<number>} source A sequence of values to calculate the sum.\n * @param {MathOptions<number>} [options] Optional options for providing a selector, thisArg and abort signal.\n * @returns {Promise<number>} A promise containing the sum of the sequence of values.\n */\nexport async function sum(\n source: AsyncIterable<number>,\n options?: MathOptions<number>\n): Promise<number>;\n/**\n * Computes the sum of a sequence of values.\n *\n * @export\n * @template T The type of values in the source sequence.\n * @param {AsyncIterable<T>} source A sequence of values to calculate the sum.\n * @param {MathOptions<T>} [options] Optional options for providing a selector, thisArg and abort signal.\n * @returns {Promise<number>} A promise containing the sum of the sequence of values.\n */\nexport async function sum<T>(source: AsyncIterable<T>, options?: MathOptions<T>): Promise<number>;\n/**\n * Computes the sum of a sequence of values.\n *\n * @export\n * @param {AsyncIterable<any>} source A sequence of values to calculate the sum.\n * @param {MathOptions<any>} [options] Optional options for providing a selector, thisArg and abort signal.\n * @returns {Promise<number>} A promise containing the sum of the sequence of values.\n */\nexport async function sum(source: AsyncIterable<any>, options?: MathOptions<any>): Promise<number> {\n const {\n ['selector']: selector = identityAsync as any,\n ['signal']: signal,\n ['thisArg']: thisArg,\n } = options || {};\n throwIfAborted(signal);\n let value = 0;\n for await (const item of wrapWithAbort(source, signal)) {\n value += await selector.call(thisArg, item, signal);\n }\n\n return value;\n}\n"]}
\No newline at end of file