Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think its best to paste some code, i.e, the code (theoretically) meeting your requirements that failed, and code that compiled and got the closest to meeting your requirements.

Hopefully someone can bridge that gap for you.



I made an example of what Im trying to do.

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.


You don't actually have to instantiate the type for a receiver function (i.e., method). There's too much missing from your code for me to understand which direction you're going but you'll likely have to use a constraint for structs which is explained here: https://github.com/akutz/go-generics-the-hard-way/blob/main/...




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: