null
null copied to clipboard
Support "unpacking" null to provide error-style handling of null values
Hi!
I'm evaluating using this package instead of maintaining my own Option[T] type.
One thing I've noticed is missing from this package is the possibility to unpack a null value into a tuple (T, bool).
Something like func (v *null.Value[T]) Unpack() (T, bool).
This does clone T which is fine for int/bool, maybe it's not fine for larger structs and it would be preferrable to return (*T, bool) ?
This allows to handle the case where the value is not initialized just like you would handle an error in idiomatic Go, i.e.
myValue, ok := nullableValue.Unpack()
if ok {
// Do something with myValue, asserted to be non-null
}
I think the use-case is valid, any thoughts ? This is not too hard to implement I think, I'm willing to contribute the change.