Rather than arguing about generics in Go again, I'd be interested in reading about how experienced Go developers solve the problems posed in this article. (He may be wrong that there's no elegant solution.) Also, if it can't be solved elegantly, perhaps adding merge() and a few other important functions to the language would be good enough? After all, Go already has the magic append() function for slices and we get q…
1) Create a "generic" version of the function using reflection / typecasts 2) Create a specific version of the function for your use-case
I don't have a ton of experience using channels. My code tends to be very imperative and I add the channel layer at the main application level rather than the library level.
So from his example:
> func merge[T](cs ...You can create a function:
func merge(cs ...interface{}) interface{}
Then call it: merged := merge(c1, c2, c3).(
You lose type safety and pay some penalty for performance. Also merge is harder to write than it would be with generics.But even languages with generics often have similar issues. For example you can't write a generic min/max in C# either.