diff --git a/utils/collection.ts b/utils/collection.ts index 98d4cf96f..d83082007 100644 --- a/utils/collection.ts +++ b/utils/collection.ts @@ -1,6 +1,17 @@ import { chooseRandom } from "./utils.ts"; export default class Collection extends Map { + maxSize?: number + + set(key: K, value: V) { + // When this collection is maxSizeed make sure we can add first + if (this.maxSize || this.maxSize === 0) { + if (this.size >= this.maxSize) return this; + } + + return super.set(key, value); + } + array() { return [...this.values()]; }