UNPKG

1.82 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAqBpD,MAAM,UAAU,IAAI,CAClB,MAAmB,EACnB,SAA+C,EAC/C,OAAa;IAEb,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;QACnC,MAAM,IAAI,SAAS,EAAE,CAAC;KACvB;IACD,MAAM,CAAC,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC9C,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,IAAI,CAAC;SACb;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","file":"find.js","sourcesContent":["import { bindCallback } from '../util/bindcallback';\n\n/**\n * Returns the value of the first element in the sequence that satisfies the provided testing function.\n * Otherwise undefined is returned.\n * @param {Iterable<T>} source Source sequence.\n * @param {function(value: T, index: number): boolean} predicate Function to execute for every item in the sequence.\n * @param {Object} [thisArg] Object to use as this when executing callback.\n * @return {T | undefined} The value of the first element in the sequence that satisfies the provided testing function.\n * Otherwise undefined is returned.\n */\nexport function find<T, S extends T>(\n source: Iterable<T>,\n predicate: (value: T, index: number) => value is S,\n thisArg?: any\n): S | undefined;\nexport function find<T>(\n source: Iterable<T>,\n predicate: (value: T, index: number) => boolean,\n thisArg?: any\n): T | undefined;\nexport function find<T>(\n source: Iterable<T>,\n predicate: (value: T, index: number) => boolean,\n thisArg?: any\n): T | undefined {\n if (typeof predicate !== 'function') {\n throw new TypeError();\n }\n const f = bindCallback(predicate, thisArg, 2);\n let i = 0;\n\n for (const item of source) {\n if (f(item, i++)) {\n return item;\n }\n }\n return undefined;\n}\n"]}
\No newline at end of file