status-sharding
Version:
Welcome to Status Sharding! This package is designed to provide an efficient and flexible solution for sharding Discord bots, allowing you to scale your bot across multiple processes or workers.
42 lines (31 loc) • 918 B
text/typescript
export default class CustomMap<K, V> extends Map<K, V> {
update(key: K, value: ((value?: Partial<V>) => V)): this {
return this.set(key, value(this.get(key)));
}
map<T>(callback: (value: V, key: K, map: this) => T): T[] {
const arr = [];
for (const [key, value] of this) {
arr.push(callback(value, key, this));
}
return arr;
}
filter(callback: (value: V, key: K, map: this) => boolean): V[] {
const arr = [];
for (const [key, value] of this) {
if (callback(value, key, this)) arr.push(value);
}
return arr;
}
find(callback: (value: V, key: K, map: this) => boolean): V | undefined {
for (const [key, value] of this) {
if (callback(value, key, this)) return value;
}
return undefined;
}
every(callback: (value: V, key: K, map: this) => boolean): boolean {
for (const [key, value] of this) {
if (!callback(value, key, this)) return false;
}
return true;
}
}