sequency
Version:
Functional sequences for processing iterable data in JavaScript
26 lines • 761 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.First = void 0;
var First = /** @class */ (function () {
function First() {
}
/**
* Returns the first element of the sequence or the first element matching `predicate` if present, otherwise throws
* an error.
*
* @param {(T) => boolean} predicate
* @returns {T}
*/
First.prototype.first = function (predicate) {
if (predicate != null) {
return this.filter(predicate).first();
}
var item = this.iterator.next();
if (item.done) {
throw new Error("No such element");
}
return item.value;
};
return First;
}());
exports.First = First;
//# sourceMappingURL=first.js.map