7 ms·
You mean like this? https://play.golang.org/p/W9PYFB6LUG https://play.golang.org/p/W9PYFB6LUG
by insertnickname 9y ago
You mean like this? https://play.golang.org/p/W9PYFB6LUG https://play.golang.org/p/W9PYFB6LUG
- keymone 9y agonotice that you had to repeat function signature on line 14 print("hello", func(msg string) { ... }) when signature is much larger it becomes very annoying. something like print("hello", Printer(msg) { ... }) would be perfect, but something something golang generics something?
- grey-area 9y agoNot sure what this has to do with generics, Go requires types for function arguments. If your anonymous function gets clumsy and too big in place, just use a named function not an anonymous one: print("hello", myprinter) https://play.golang.org/p/3sNOeVIhqi https://play.golang.org/p/3sNOeVIhqi
- keymone 9y agopoint is typedefs aren't reusable at anonymous function declarations. imo that sucks. that's all i wanted to say.
- davidarkemp2 9y agoYou could always declare the method on the Printer type... https://play.golang.org/p/4MG8kgGEGM https://play.golang.org/p/4MG8kgGEGM
- keymone 9y agowhere's the anonymous function with reuse of typedef in there?
- jerf 9y agoNo, it's just a syntax issue, not a generics issue. Are there any manifestly-typed languages that work that way, though? I'm having trouble thinking of one, though given the number out there I won't be surprised if there is.
- keymone 9y agomaybe there are none, but wouldn't that be really nice?