more examples
This commit is contained in:
22
gobyexample/closures.go
Normal file
22
gobyexample/closures.go
Normal file
@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func intSeq() func() int {
|
||||
i := 0
|
||||
return func() int {
|
||||
i++
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
nextInt := intSeq()
|
||||
|
||||
fmt.Println(nextInt())
|
||||
fmt.Println(nextInt())
|
||||
fmt.Println(nextInt())
|
||||
|
||||
newInts := intSeq()
|
||||
fmt.Println(newInts())
|
||||
}
|
Reference in New Issue
Block a user