function type definition in Go
tags: learning go programming
content
- in Go, we can see code like this
type Operation(int, int) int- this defines a
function type - it can be used like:
func Add(a, b int) int { return a + b }
func Substract(a, b int) int { return a - b }
func Calculate(a, b int, op Operation) {
return op(a, b)
}