Professional Documents
Culture Documents
Closures PDF
Closures PDF
Closures PDF
package main
import "fmt"
This function intSeq returns another function, which func intSeq() func() int {
we define anonymously in the body of intSeq. The i := 0
returned function closes over the variable i to form a return func() int {
i++
closure.
return i
}
}
func main() {
$ go run closures.go
1
2
3
1