markphelps / optional

Optional is a library of optional Go types
https://godoc.org/github.com/markphelps/optional
MIT License
209 stars 19 forks source link

do no crash when calling Get() on empty optional #7

Closed roudy16 closed 5 years ago

roudy16 commented 5 years ago

Please note that I updated some test files as well.

roudy16 commented 5 years ago

I checked Java and C++ standard Optional implementations and it looks like throwing an exception is what they both chose to do. Having the non-nil error seems to be the Go analog to throwing an exception. But yeah, hopefully people aren't out there just ignoring errors, having optional setup this way and ignoring the error could cause a tough bug to find.

markphelps commented 5 years ago

Cheers! Thanks for this. I'll update the README to call this situation out. The godocs already state that an error is returned if it's not present so thinking about it some more, I feel like it's expected behavior.

I'll cut a new release tonight. Thanks again! 🍻