Skip to content

Instantly share code, notes, and snippets.

@n2p5
Created July 7, 2023 18:51
Show Gist options
  • Save n2p5/749d14370f9269283f349e6c42f7c77c to your computer and use it in GitHub Desktop.
Save n2p5/749d14370f9269283f349e6c42f7c77c to your computer and use it in GitHub Desktop.
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