Skip to content

Support "unpacking" null to provide error-style handling of null values #86

@AlisCode

Description

@AlisCode

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions