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[i comparable, o any](f func(in i) o) func(in i) o {
|
|
cache := make(map[i]o, 0)
|
|
return func(in i) o {
|
|
cached, has := cache[in]
|
|
if has {
|
|
return cached
|
|
}
|
|
|
|
out := f(in)
|
|
cache[in] = out
|
|
return out
|
|
}
|
|
}
|