3 ms·
No, you just define it ad hoc locally. type OptionInt enum { Int(int), None } Yeah this means you would have to write that line for every type, but that’s
by throwaway894345 4y ago
No, you just define it ad hoc locally.
type OptionInt enum { Int(int), None }
Yeah this means you would have to write that line for every type, but that’s pretty in-line with Go’s philosophy that a little bit of copying is better than a little dependency. But the people who optimize for keystrokes above all else will take issue with it.
- kaba0 4y agoThat’s probably the only amount of copying that might be okay. Anything more than that and you have n places of code living independently of each other, making refactoring/bugfixing impossible.
- throwaway894345 4y agoYes, if the code is complex, this becomes tedious. But you'd be surprised how often this sort of thing suffices. It turns out not everything needs a dozen combinator methods. See also a linked list implementation: `type List struct { Next *List, Item int }`.