UNPKG

1.46 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/count.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,KAAK,CAAI,MAAmB,EAAE,OAAgC;IAC5E,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,SAAS,GAAG,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACtF,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;YACpC,CAAC,EAAE,CAAC;SACL;KACF;IAED,OAAO,CAAC,CAAC;AACX,CAAC","file":"count.js","sourcesContent":["import { OptionalFindOptions } from './findoptions';\n\n/**\n * Returns a promise that represents how many elements in the specified 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 {Iterable<T>} source An iterable sequence that contains elements to be counted.\n * @param {OptionalFindOptions<T>} [options] The options for a predicate for filtering and thisArg for binding.\n * @returns {number} The number of matching elements for the given condition if provided, otherwise\n * the number of elements in the sequence.\n */\nexport function count<T>(source: Iterable<T>, options?: OptionalFindOptions<T>): number {\n const { ['thisArg']: thisArg, ['predicate']: predicate = () => true } = options || {};\n let i = 0;\n\n for (const item of source) {\n if (predicate.call(thisArg, item, i)) {\n i++;\n }\n }\n\n return i;\n}\n"]}
\No newline at end of file