func memoize[T comparable, U any](f func(T) U) func(T) U {
memory := make(map[T]U)
return func(t T) U {
if u, seen := memory[t]; seen {
return u
}
u := f(t)
memory[t] = u
return u
}
}
func memoize[T comparable, U any](f func(T) U) func(T) U {
memory := make(map[T]U)
return func(t T) U {
if u, seen := memory[t]; seen {
return u
}
u := f(t)
memory[t] = u
return u
}
}