This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExtendedMap<K, V> extends Map<K, V> { | |
update(key: K, updater: (value: V, key: K) => V, reset: V = undefined) { | |
if (this.has(key)) { | |
this.set(key, updater(this.get(key), key)); | |
} | |
else this.set(key, reset); | |
} | |
filter(predicate: (value: V, key: K) => boolean) { | |
const newMap = new ExtendedMap<K, V>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debounce = <F extends (...args: any[]) => any>(fn: F, delay: number) => { | |
let timeout: NodeJS.Timeout; | |
const debounced = (...args: any[]) => { | |
clearTimeout(timeout); | |
timeout = setTimeout(() => fn(...args), delay); | |
}; | |
return debounced as (...args: Parameters<F>) => ReturnType<F>; | |
}; | |