mirror of
https://github.com/samuelncui/acp.git
synced 2025-12-23 05:05:15 +00:00
16 lines
237 B
Go
16 lines
237 B
Go
package acp
|
|
|
|
func Cache[K comparable, V any](f func(in K) V) func(in K) V {
|
|
cache := make(map[K]V, 0)
|
|
return func(in K) V {
|
|
cached, has := cache[in]
|
|
if has {
|
|
return cached
|
|
}
|
|
|
|
out := f(in)
|
|
cache[in] = out
|
|
return out
|
|
}
|
|
}
|