August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, you are going to learn how to implement a Go function that returns another function using the Go code of returnFunction.go, which will be presented in three segments. The first code segment of returnFunction.go is as follows:
package main
import (
"fmt"
)
func funReturnFun() func() int {
i := 0
return func() int {
i++
return i * i
}
}
As you can see from the implementation of funReturnFun(), its return value is an anonymous function (func() int).
The second code segment from returnFunction.go contains the following code:
func main() {
i := funReturnFun()
j := funReturnFun()
In this code, you call funReturnFun() two times and assign its return value, which is a function, to two separate ...
Read now
Unlock full access