Skip to content

Instantly share code, notes, and snippets.

@lalizita
Created November 2, 2022 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lalizita/ccdca623890eba67c9a6fa01c4116e24 to your computer and use it in GitHub Desktop.
Save lalizita/ccdca623890eba67c9a6fa01c4116e24 to your computer and use it in GitHub Desktop.
Example of anonymous function with Go for a medium article
func main() {
x := sumNumber()
fmt.Println(x())
fmt.Println(x())
}
func sumNumber() func() int {
number := 1
return func() int {
number++
return number
}
}
// OUTPUT
// 1
// 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment