UNPKG

1.8 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/first.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;;;;;;;GAQG;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;IACV,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QACtD,IAAI,MAAM,SAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE;YACrD,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","file":"first.js","sourcesContent":["import { wrapWithAbort } from './operators/withabort';\nimport { throwIfAborted } from '../aborterror';\nimport { OptionalFindOptions } from './findoptions';\n\n/**\n * Returns the first element of an async-iterable sequence that matches the predicate if provided, or undefined if no such element exists.\n *\n * @export\n * @template T The type of the elements in the source sequence.\n * @param {AsyncIterable<T>} source Source async-enumerable sequence.\n * @returns {(Promise<S | undefined>)} A Promise containing the first element in the async-iterable sequence,\n * or a default value if no such element exists.\n */\nexport async function first<T>(\n source: AsyncIterable<T>,\n options?: OptionalFindOptions<T>\n): Promise<T | undefined> {\n const { ['signal']: signal, ['thisArg']: thisArg, ['predicate']: predicate = async () => true } =\n options || {};\n throwIfAborted(signal);\n let i = 0;\n for await (const item of wrapWithAbort(source, signal)) {\n if (await predicate!.call(thisArg, item, i++, signal)) {\n return item;\n }\n }\n\n return undefined;\n}\n"]}
\No newline at end of file