UNPKG

sequency

Version:

Functional sequences for processing iterable data in JavaScript

34 lines 1.17 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.LastOrNull = void 0; var LastOrNull = /** @class */ (function () { function LastOrNull() { } /** * Returns the last element of the sequence or the last element matching `predicate` if present, otherwise returns `null`. * * @param {(value: T) => boolean} predicate * @returns {T} */ LastOrNull.prototype.lastOrNull = function (predicate) { if (predicate != null) { return this.filter(predicate).lastOrNull(); } var result = null; for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) { result = item.value; } return result; }; /** * Returns the last element of the sequence or the last element matching `predicate` if present, otherwise returns `null`. * * @param {(value: T) => boolean} predicate * @returns {T} */ LastOrNull.prototype.findLast = function (predicate) { return this.lastOrNull(predicate); }; return LastOrNull; }()); exports.LastOrNull = LastOrNull; //# sourceMappingURL=lastOrNull.js.map