2 ms·
I've had a play around with Go generics, and from what I can tell it boils down to passing the type parameter down the chain, from the concrete to the general,
by neilwilson 5y ago
I've had a play around with Go generics, and from what I can tell it boils down to passing the type parameter down the chain, from the concrete to the general, to the point where a function needs to create a structure, and then returning that structure back up again, modifying the structure with functions and methods as you go.
Rather than creating the structure and passing it down the chain to be modified via typecasts as previously.
Pretty much everything else ends up being limited by interface types being unable to reference structure attributes directly, but requiring method signatures. So it becomes more complicated to reference all types that have an 'ID' attribute for example.
With some types I ended up with so many getter and setter functions to enable generics, that it was better to revert back to 'go generate'.
Perhaps it works better with pure container types that can take 'any'.