-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
Milestone
Description
Every individual type can be compared to its zero value (func() == nil, for example), but there is no way to write this code today without using package reflect:
func IsZero[T any](t T) bool {
return t == zero
}It must instead be:
func IsZero[T any](t T) bool {
return reflect.ValueOf(&t).Elem().IsZero()
}I propose adding a built in constant zero that can be tested for equality with any type.
It could also be returned, as in
if err != nil {
return zero, err
}