lean into examples
This commit is contained in:
20
examples/closures/closures.go
Normal file
20
examples/closures/closures.go
Normal file
@@ -0,0 +1,20 @@
|
||||
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.
|
||||
Reference in New Issue
Block a user