UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

33 lines (31 loc) 1.25 kB
import { __values } from "tslib"; /** * Returns the value of the first element in the provided iterable that satisfies the provided testing function. * * @template T The type of the elements in the source sequence. * @param {Iterable<T>} source An iterable sequence whose elements to apply the predicate to. * @param {FindOptions<T>} options The options for a predicate for filtering, thisArg for binding and AbortSignal for cancellation. * @returns {(T | undefined)} The first element that matches the predicate. */ export function find(source, options) { var e_1, _a; var thisArg = options["thisArg"], predicate = options["predicate"]; var i = 0; try { for (var source_1 = __values(source), source_1_1 = source_1.next(); !source_1_1.done; source_1_1 = source_1.next()) { var item = source_1_1.value; if (predicate.call(thisArg, item, i++)) { return item; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (source_1_1 && !source_1_1.done && (_a = source_1.return)) _a.call(source_1); } finally { if (e_1) throw e_1.error; } } return undefined; } //# sourceMappingURL=find.js.map