UNPKG

1.59 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/last.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,IAAI,CAAI,MAAmB,EAAE,OAAgC;IAC3E,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;IACV,IAAI,MAAqB,CAAC;IAC1B,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,IAAI,SAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;YACvC,MAAM,GAAG,IAAI,CAAC;SACf;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","file":"last.js","sourcesContent":["import { OptionalFindOptions } from './findoptions';\n\n/**\n * Returns the last element of an 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 {Iterable<T>} source The source iterable sequence.\n * @param {OptionalFindSubclassedOptions<T, S>} [options] The options which include an optional predicate for filtering,\n * thirArg for binding, and abort signal for cancellation\n * @returns {(S | undefined)} The last value that matches the optional predicate or last item, otherwise undefined.\n */\nexport function last<T>(source: Iterable<T>, options?: OptionalFindOptions<T>): T | undefined {\n const { ['thisArg']: thisArg, ['predicate']: predicate = () => true } = options || {};\n let i = 0;\n let result: T | undefined;\n for (const item of source) {\n if (predicate!.call(thisArg, item, i++)) {\n result = item;\n }\n }\n\n return result;\n}\n"]}
\No newline at end of file