How to implement cache/memoize #2789
-
Hi, congrats with V1! 🎉 For example, JavaScript: // Map can use arbitrary types for keys: Objects, Arrays, Functions and so on
const cache = new Map();
const fnUsingCache = (arg) => {
if (cache.has(arg)) {
return cache.get(arg)
}
// resp calculation and cache population
} For example, Golang: // Map can use pointers as keys
var cache = map[interface{}]interface{}
func FnUsingCache[T, R Any](arg *T) R {
if cache[arg] != nil {
return cache[arg]
}
// resp calculation and cache population
} |
Beta Was this translation helpful? Give feedback.
Answered by
lpil
Mar 21, 2024
Replies: 1 comment 4 replies
-
Hello! In a function language you pass the cache around as we make state explicit. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dict does not use strings for keys, you can use anything.