1 comment

[ 2.8 ms ] story [ 19.3 ms ] thread
The main point of the Option type (and Result) is not because it panics when you call `unwrap`.

It's about all the operations you can chain with it:

  - and_then
  - ok_or_else
  - map
  - ...
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:

  - no switch on a generic type
  - method must have no type parameter
  - union types cannot be used for anything else than a type constraint
  - probably other things I did not notice yet
Clearly, the language designers don't want you to use functional abstractions like this, for some reason.