You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the Get method returns an error if null or unspecified, which makes sense when getting however if a user is explicitly calling a method named something like GetOrZero, their intention is to get the Zero value. The problem stems from having to ignore the error which can cause issues / annoyances with linters. This also allows using Nullable more easily as you can just add this everywhere instead of having a migration from bool -> Nullable[bool] once the use case comes up.
The method's signature would be pretty simple.
current implementation.
func (tNullable[T]) Get() (T, error) {
varemptyTift.IsNull() {
returnempty, errors.New("value is null")
}
if!t.IsSpecified() {
returnempty, errors.New("value is not specified")
}
returnt[true], nil
}
addition:
func (tNullable[T]) GetOrZero() T {
val, _:=Get()
returnval
}
I am willing to open a PR if this is approved. Thank you!
Activity