5 ms·
brouhaha go bad. Why are you writing an add function when 1 + 1 will do? I mean I know there's better examples out there, but in practice I've not missed a lac
by Cthulhu_ 5y ago
brouhaha go bad. Why are you writing an add function when 1 + 1 will do?
I mean I know there's better examples out there, but in practice I've not missed a lack of generics in Go yet. Mind you, I'm not writing libraries for e.g. json parsing.
Actually there is one place in my application where I use interface{}, it's a bit of code that converts values to XML strings, but it needs different logic for different types. I don't think generics will solve that: https://go.dev/play/p/TtwyNZ7oOPx https://go.dev/play/p/TtwyNZ7oOPx
- jatone 5y agoi think constraints will help which are part of generics at least you'll be able to limit the types your functions accept. but otherwise no, generics do not solve sum types by themselves.