UNPKG

1.97 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/count.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,MAAwB,EACxB,OAAgC;IAEhC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,SAAS,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,GAC7F,OAAO,IAAI,EAAE,CAAC;IAChB,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACtD,IAAI,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE;YAClD,CAAC,EAAE,CAAC;SACL;KACF;IAED,OAAO,CAAC,CAAC;AACX,CAAC","file":"count.js","sourcesContent":["import { wrapWithAbort } from './operators/withabort';\nimport { throwIfAborted } from '../aborterror';\nimport { OptionalFindOptions } from './findoptions';\n\n/**\n * Returns a promise that represents how many elements in the specified async-iterable sequence satisfy a condition\n * otherwise, the number of items in the sequence.\n *\n * @export\n * @template T The type of elements in the source collection.\n * @param {AsyncIterable<T>} source An async-iterable sequence that contains elements to be counted.\n * @param {OptionalFindOptions<T>} [options] The options for a predicate for filtering, thisArg for binding and AbortSignal for cancellation.\n * @returns {Promise<number>} The number of matching elements for the given condition if provided, otherwise\n * the number of elements in the sequence.\n */\nexport async function count<T>(\n source: AsyncIterable<T>,\n options?: OptionalFindOptions<T>\n): Promise<number> {\n const { ['signal']: signal, ['thisArg']: thisArg, ['predicate']: predicate = async () => true } =\n options || {};\n throwIfAborted(signal);\n let i = 0;\n\n for await (const item of wrapWithAbort(source, signal)) {\n if (await predicate.call(thisArg, item, i, signal)) {\n i++;\n }\n }\n\n return i;\n}\n"]}
\No newline at end of file