@livy/util
Version:
Common utilities for the Livy logger
29 lines (28 loc) • 829 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GatedSet = void 0;
const helpers_1 = require("./helpers");
const validatable_set_1 = require("./validatable-set");
class GatedSet extends validatable_set_1.ValidatableSet {
constructor(validator, iterable) {
if (typeof validator !== 'function') {
throw new TypeError(`The validator must be a function, ${(0, helpers_1.getObviousTypeName)(validator)} given`);
}
super();
this.validator = validator;
if (iterable) {
for (const value of iterable) {
this.add(value);
}
}
}
/**
* @inheritdoc
*/
add(value) {
this.validator(value);
super.add(value);
return this;
}
}
exports.GatedSet = GatedSet;