(no title)
Kostarrr | 3 years ago
But you could probably achieve that using go's not-well-known sum types, e.g. like this
https://github.com/FSMaxB/type-safe-builder-experiment/blob/...
Kostarrr | 3 years ago
But you could probably achieve that using go's not-well-known sum types, e.g. like this
https://github.com/FSMaxB/type-safe-builder-experiment/blob/...
tsimionescu|3 years ago
For example, this doesn't work [0]:
[0] https://go.dev/play/p/1CnieCLqESCKostarrr|3 years ago
jchw|3 years ago
tsimionescu|3 years ago
It's a kind of sum type, but it can only be used to constrain types for a generic parameter.
That is, you can define `func foo[T StaticOptional[int]](x T)` and then call it as `foo(StaticNone{})` or `foo(StaticSome[int]{123})`, but you can't do `func foo() StaticOptional[int]` or even `func foo[T StaticOptional[int]]() T {return StaticNone{} }`.
Koiwai|3 years ago
https://go.dev/play/p/88We4TDhGQc
dolmen|3 years ago