UNPKG

1.93 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/findindex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,MAAwB,EACxB,OAAuB;IAEvB,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACvF,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,EAAE,MAAM,CAAC,EAAE;YACpD,OAAO,CAAC,CAAC;SACV;KACF;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC","file":"findindex.js","sourcesContent":["import { wrapWithAbort } from './operators/withabort';\nimport { throwIfAborted } from '../aborterror';\nimport { FindOptions } from './findoptions';\n\n/**\n * Returns the a Promise containing the index of the first element in the array that satisfies the provided testing function.\n * Otherwise, it returns a Promise with -1, indicating that no element passed the test.\n *\n * @export\n * @template T The type of the elements in the source sequence.\n * @param {AsyncIterable<T>} source An async-iterable sequence whose elements to apply the predicate to.\n * @param {FindOptions<T>} options The options for a predicate for filtering, thisArg for binding and AbortSignal for cancellation.\n * @returns {Promise<number>} A promise containing the index of the first element in the array that passes the test. Otherwise, -1.\n */\nexport async function findIndex<T>(\n source: AsyncIterable<T>,\n options: FindOptions<T>\n): Promise<number> {\n const { ['signal']: signal, ['thisArg']: thisArg, ['predicate']: predicate } = 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 return i;\n }\n }\n return -1;\n}\n"]}
\No newline at end of file