I am failing to understand whats happening with Equal (u T) bool. Is it a method within a function? Also what is the difference of a method and a function. I understand that this function is taking in t of type T and return true or false if t=u.
type T int
func (t T) Equal (u T) bool {return t==u}
That's a method declaration, and since methods in Go are just functions with a receiver they are declared using the keyword func
.
func (t T) Equal (u T) bool {return t==u}
1 2 3 4 5 6 7 8
For comparison, a function that does the same thing would be declared as such:
func Equal (t T, u T) bool {return t==u}
(no reciever, but takes two arguments)