sequency
Version:
Functional sequences for processing iterable data in JavaScript
33 lines • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.FirstOrNull = void 0;
var FirstOrNull = /** @class */ (function () {
function FirstOrNull() {
}
/**
* Returns the first element of the sequence or the first element matching `predicate` if present, otherwise returns `null`.
*
* @param {(T) => boolean} predicate
* @returns {T}
*/
FirstOrNull.prototype.firstOrNull = function (predicate) {
if (predicate != null) {
return this.filter(predicate).firstOrNull();
}
var item = this.iterator.next();
return item.done
? null
: item.value;
};
/**
* Returns the first element of the sequence or the first element matching `predicate` if present, otherwise returns `null`.
*
* @param {(T) => boolean} predicate
* @returns {T}
*/
FirstOrNull.prototype.find = function (predicate) {
return this.firstOrNull(predicate);
};
return FirstOrNull;
}());
exports.FirstOrNull = FirstOrNull;
//# sourceMappingURL=firstOrNull.js.map