Re:Trying Out Generics in Go
by 1_player on Thursday December 16, 2021 @04:12PM
(#29583991)
I don't understand your example, `isSet` is always true and can never be false. Missed something?
[ Parent
| on HN ]
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]()