/**
* ht vue, lo
* Cache a function
*/
function cached (
fn: Function,
resolver: Function
): Function {
const cache = new WeakMap()
return (function(str) {
const key = resolver ? resolver(str) : str
return cache.has(key)
? cache.get(key)
: cache.set(key, fn(str))
})
}
Created
February 14, 2020 14:01
-
-
Save matthewstokeley/9001abe535195fb7ed4e7ecd211acba0 to your computer and use it in GitHub Desktop.
pure-function-patterns
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment