Passing Functions as Parameters
In GO, a function is also a type. Two functions are of the same type if they have the same arguments and the same return values.
When passing a function as an argument to another function, the exact signature of the function must be specified in the argument list.
// Here, the Arithmetic function receives
// as an argument a function that
// must have the form of func(int, int) int.
func Arithmetic(x, y int, f func(int, int) int) int {
return f(x, y)
🇧🇷
// The Add function can be
// passed to the Arithmetic function,
// as it has the required form, or signature.
func Sum(x, y int) int {
return x + y
}