Skip to content

Instantly share code, notes, and snippets.

@MaikelVeen
Created March 6, 2022 11:59
Show Gist options
  • Save MaikelVeen/21674c68b1cb2aa294fc11787f6ead31 to your computer and use it in GitHub Desktop.
Save MaikelVeen/21674c68b1cb2aa294fc11787f6ead31 to your computer and use it in GitHub Desktop.
An example of an closure / anonymous function
// squares returns a function that returns
// the next square number each time it is called.
func squares() func() int {
var x int
return func() int {
x++
return x * x
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment