-
-
Save TrooperT/103eef82acb276193b7e129b86e7ca45 to your computer and use it in GitHub Desktop.
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
| func typeCache[T any](compute func(t reflect.Type) T) func(t reflect.Type) T { | |
| cache := map[reflect.Type]T{} | |
| return func(t reflect.Type) T { | |
| if v, ok := cache[t]; ok { | |
| return v | |
| } | |
| v := compute(t) // but compute cant recurse | |
| cache[t] = v | |
| return v | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment