Prolly. Except OP specifically asked about "not that" :) On Tue, Aug 4, 2020 at 5:30 PM Andrei Tudor Călin <m...@acln.ro> wrote:
> I feel like https://go2goplay.golang.org/p/RLn9BXjU1OR is a better > compromise than having two functions. > > On Tue, Aug 4, 2020 at 5:50 PM 'Axel Wagner' via golang-nuts < > golang-nuts@googlegroups.com> wrote: > >> 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 >> <https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHBjg%3Dp7HTOAfVx-q9vvnJsdcQ0ozRt_Uwsn2yF2nW6jg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Andrei Călin > -- 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/CAEkBMfHyGWr-at5a7yc8t-URgK0Oobb_Re6_T%3D_DJdVXXpX28Q%40mail.gmail.com.