Juliusz Chroboczek
unread,Aug 4, 2020, 10:32:17 AM8/4/20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
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.