UNPKG

2.08 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/last.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,IAAI,CACxB,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,MAAqB,CAAC;IAC1B,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,MAAM,GAAG,IAAI,CAAC;SACf;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","file":"last.js","sourcesContent":["import { wrapWithAbort } from './operators/withabort';\nimport { throwIfAborted } from '../aborterror';\nimport { OptionalFindOptions } from './findoptions';\n\n/**\n * Returns the last element of an async-iterable sequence that satisfies the condition in the predicate if given\n * otherwise the last item in the sequence, or a default value if no such element exists.\n *\n * @export\n * @template T The type of elements in the source sequence.\n * @param {AsyncIterable<T>} source The source async-iterable sequence.\n * @param {OptionalFindOptions<T, S>} [options] The options which include an optional predicate for filtering,\n * thirArg for binding, and abort signal for cancellation\n * @returns {(Promise<S | undefined>)} A promise containing the last value that matches the optional predicate or last item, otherwise undefined.\n */\nexport async function last<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 let result: T | undefined;\n for await (const item of wrapWithAbort(source, signal)) {\n if (await predicate!.call(thisArg, item, i++, signal)) {\n result = item;\n }\n }\n\n return result;\n}\n"]}
\No newline at end of file