UNPKG

@livy/util

Version:
25 lines (24 loc) 682 B
import { getObviousTypeName } from './helpers.mjs'; import { ValidatableSet } from './validatable-set.mjs'; export class GatedSet extends ValidatableSet { constructor(validator, iterable) { if (typeof validator !== 'function') { throw new TypeError(`The validator must be a function, ${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; } }