3 ms·
Thanks for your reply. I made an example of what Im trying to do. One thing I didnt specify is the function used is a receiver function. For some reason this m
by wara23arish 4y ago
Thanks for your reply.
I made an example of what Im trying to do. One thing I didnt specify is the function used is a receiver function. For some reason this means the type had to be instantiated on the receiver itself Spotter in this case.
https://goplay.tools/snippet/Vj7uVMi0mWn https://goplay.tools/snippet/Vj7uVMi0mWn
Basically have two different types that implement an interface, pass them into a receiver function in a composite type (array,slice).
Part of the issue is that you cant have the receiver function without defining instantiating the type on the receiver Spotter in this case.
- khyryk 4y agoIf I'm, again, understanding what's happening, as the example above doesn't compile in its current state, then you'll probably run into this limitation: https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#No-parameterized-methods https://go.googlesource.com/proposal/+/refs/heads/master/des... I believe the most simple fix would be to have a separate function which is generic that takes in the struct along with the slice of T with the constraints that apply to it.