No, that's not possible. A generic function can only work with *either* built in operators *or* methods. So, you always need to have two functions: https://go2goplay.golang.org/p/YuzSzDAOEo2
On Tue, Aug 4, 2020 at 4:32 PM Juliusz Chroboczek <j...@irif.fr> wrote: > I'd be grateful if people could give me an example to help me understand > the generics draft. Suppose I've got these two functions: > > func MemberInt(x int, a []int) bool { > for _, v := range a { > if v == x { > return true > } > } > return false > } > > func MemberIP(x net.IP, a []net.IP) bool { > for _, v := range a { > if v.Equal(x) { > return true > } > } > return false > } > > I can see how to write a generic "Member" function that takes an extra > equality predicate; but is there a way to write a function that > generalises both functions above without requiring the extra parameter? > > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/87v9hytrcn.fsf%40pirx.irif.fr > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHBjg%3Dp7HTOAfVx-q9vvnJsdcQ0ozRt_Uwsn2yF2nW6jg%40mail.gmail.com.