Show HN: Goptional, an Option library for Go I made in half an hour (github.com)
Hey HN,
With the release of Go 1.18, adding generics, I thought it might be fun to make a tiny Options library to bring some of that Rustacean Panicking magic into Go.
I'd love any feedback or contributions to make it, well, _less_ crappy!
Cheers.
1 comment
[ 2.8 ms ] story [ 19.3 ms ] threadIt's about all the operations you can chain with it:
This allows you to chain computations and "defer" the error handling at the end, without requiring exceptions/goto-jumps.Your implementation, and the 10 others I've seen since the release, has strictly no advantage over using `interface{}` with a `nil` check.
Go 1.18 cannot have an Option type or a Result type because its generics are painfully too restrictive:
Clearly, the language designers don't want you to use functional abstractions like this, for some reason.