Description
I was able to find similar discussions on stdlib generic Slice and Map packages, but I was unable to find anything about Optional
. If this was just a case of poor searching (or poor indexing), then my apologies - please close this.
At the moment, there are two ways to handle optionality - either through the type's zero value (eg Time
), or by using a pointer type.
However, using a pointer type creates a degree of ambiguity. Sometimes a pointer is chosen for mutability reasons, and nil
is never intended to be present. Likewise sometimes a pointer is chosen only for performance reasons.
It has been noted in many places that with the new Go generics system, creating an Optional[T any]
type to represent a value that may or may not be filled is rather trivial.
However, if the creation and use of such types is left up to the ecosystem, it is likely that at least a handful of incompatible implementations may surface - whereas if the stdlib held the main implementation then everyone else could build on top of it as needed.