UNPKG

@reactivex/ix-es5-esm

Version:

The Interactive Extensions for JavaScript

32 lines (30 loc) 1.21 kB
import { __values } from "tslib"; /** * Returns the first element of an iterable sequence that matches the predicate if provided, or undefined if no such element exists. * * @template T The type of the elements in the source sequence. * @param {Iterable<T>} source Source async-enumerable sequence. * @returns {(S | undefined)} The first element in the iterable sequence, or undefined if no such element exists. */ export function first(source, options) { var e_1, _a; var _b = options || {}, thisArg = _b["thisArg"], _c = _b["predicate"], predicate = _c === void 0 ? function () { return true; } : _c; 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=first.js.map