|
|
|
|
|
by khyryk
1346 days ago
|
|
What I'm getting from that is that you want some func that takes in a []T where the T is constrained to some set of types, and you want to call the func without having to specify the type that you're passing in using square brackets every time. If that's correct, then is this what you need? https://go.dev/play/p/_e-Uipgo5OQ It seems quite straightforward so I think I'm missing some context, but this can be a start. |
|
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 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.