-
-
Save n2p5/749d14370f9269283f349e6c42f7c77c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func nextEven() func() uint64 { | |
var state uint64 | |
return func() uint64 { | |
state += 2 | |
return state | |
} | |
} | |
func main() { | |
next := nextEven() | |
for i := 0; i < 10; i++ { | |
fmt.Println(next()) | |
} | |
} | |
// OUTPUT: | |
// 2 | |
// 4 | |
// 6 | |
// 8 | |
// 10 | |
// 12 | |
// 14 | |
// 16 | |
// 18 | |
// 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment