Closed roudy16 closed 5 years ago
Ahh good catch! Yes I think it makes sense to return the zero value. I don't think panicking is a good UX. A PR would be greatly appreciated 🙇
The only thing I worry about is that the point of using optional types is to be able differentiate between a default value and a value that wasn't set.. but.. it's common knowledge in the Go community to always check the result of error
first.. so I think this is ok.
Should be fixed in #7
Calling Get() on an empty optional leads to a nil pointer dereference. It seems like it would be okay to return a zero value with a non-nil error in the case that Get() fails. I'm willing to do this work if you approve of my suggested fix, I also understand if crashing is the desired behavior. In the case that you want the crash the Get() method doesn't seem like it needs to call Present().
Crashing example:
Suggested fix for int64 type: