3 ms·
It would be really interesting to see specific examples for this - can you give a short example in code or pseudo-code of somewhere you really wanted them and d
by grey-area 13y ago
It would be really interesting to see specific examples for this - can you give a short example in code or pseudo-code of somewhere you really wanted them and didn't have them, and how they would improve things? There is a generic append, but do you mean sorting lists or something else? Apologies if this is obvious, but it would be enlightening for those not familiar with generics from other languages.
- friendly_chap 13y agoLet's take a basic list operation, map. Map takes a transforming function and a list, and transforms each element. type MyString string func NewMyString(s string) MyString{return MyString(s)} a := []string{"A", "B", "C"} If you want to create a []MyString from []string, now you have to loop over that and transform by hand, with generics you could do map(NewMyString, a).
- grey-area 13y agoThanks