Mark McGranaghan 25dc8ca800 full book wip
2012-10-02 18:29:58 -07:00

23 lines
351 B
Go

// ## Closures
package main
import "fmt"
func makeEvenGenerator() func() uint {
i := uint(0)
return func() uint {
i += 2
return i
}
}
func main() {
nextEven := makeEvenGenerator()
fmt.Println(nextEven())
fmt.Println(nextEven())
fmt.Println(nextEven())
}
// todo: note example of first-class functions.