User Defined Function Types in Golang
Golang also support to define our own function types.
The modified version of above program with function types as below:
Example
package main
import "fmt"
type First func(int) int
type Second func(int) First
func squareSum(x int) Second {
return func(y int) First {
return func(z int) int {
return x*x + y*y + z*z
}
}
}
func main() {
// 5*5 + 6*6 + 7*7
fmt.Println(squareSum(5)(6)(7))
}
Most Helpful This Week
Simple function with return value in Golang
Closures Functions in Golang
The return values of a function can be named in Golang
Golang Passing Address to a Function
What is Function in Golang
Naming Conventions for Golang Functions
Higher Order Functions in Golang
Simple function with parameters in Golang
Anonymous Functions in Golang
Golang Functions Returning Multiple Values
Creating a Function in Golang