Hacker News new | ask | show | jobs
by 1_player 1653 days ago
I don't understand your example, `isSet` is always true and can never be false. Missed something?
2 comments

It works because it's false when uninitialized (as default value). So if not initialized it represents Nothing value. When it is initialized it's Just T.
The only time `IsSet` would be false is when `NewOption` was not used to initialize the value.

e.g.

  var o Option[int32]
or could have `None` helper

  func None[T any]() Option[T] { return Option[T]{} }

  o := None[int32]()