Hi
I have a small library with a struct Option[T]
. Is there a way to check if an object is an instance of Option
without it’s generic type, cast it and get it’s inner type?
package main
type Option[T] struct{
Value T
IsSome bool
}
func (o Option[T]) InnerType() reflect.Type {
return reflect.TypeOf((*T)(nil)).Elem()
}
This works so far. What I want to achieve is:
func IsOption(o any) bool {
??
}
func GetInnerType(o any) *reflect.Type {
if !IsOption(o) {
return nil
}
opt := o.(Option)
typ := opt.InnerType()
return &typ
}