-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.ProposalProposal-Acceptedhelp wanted
Milestone
Description
Many encoding packages have a custom internal "isEmptyValue" function. The functionality is pretty much identical. This expands to other packages that use reflect, such as an ORM (is primary key set?). It would be useful to have a standard "IsZero" method on reflect.Value, something like this (copied from encoding/xml): func (v Value) IsZero() bool { switch v.Kind() { case reflect.Array, reflect.Map, reflect.Slice, reflect.String: return v.Len() == 0 case reflect.Bool: return !v.Bool() case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return v.Int() == 0 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: return v.Uint() == 0 case reflect.Float32, reflect.Float64: return v.Float() == 0 case reflect.Interface, reflect.Ptr: return v.IsNil() } return false }
bradfitz, thesyncim, DeedleFake, ssoroka, clarketm and 2 more
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.ProposalProposal-Acceptedhelp wanted