Skip to content

Instantly share code, notes, and snippets.

@ambalabanov
Created March 23, 2020 08:30
Show Gist options
  • Save ambalabanov/e09b6220c96250cf8db96409c112cbcf to your computer and use it in GitHub Desktop.
Save ambalabanov/e09b6220c96250cf8db96409c112cbcf to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
numGenerator := generator()
for i := 0; i < 5; i++ {
fmt.Print(numGenerator(), "\t")
}
}
// This function returns another function
func generator() func() int { // Outer function
var i = 0
return func() int { // Inner function
i++
return i
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment