UNPKG

1.29 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/first.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;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;IACV,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,IAAI,SAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;YACvC,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","file":"first.js","sourcesContent":["import { OptionalFindOptions } from './findoptions';\n\n/**\n * Returns the first element of an 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 {Iterable<T>} source Source async-enumerable sequence.\n * @returns {(S | undefined)} The first element in the iterable sequence, or undefined if no such element exists.\n */\nexport function first<T>(source: Iterable<T>, options?: OptionalFindOptions<T>): T | undefined {\n const { ['thisArg']: thisArg, ['predicate']: predicate = () => true } = options || {};\n let i = 0;\n for (const item of source) {\n if (predicate!.call(thisArg, item, i++)) {\n return item;\n }\n }\n\n return undefined;\n}\n"]}
\No newline at end of file