Created
March 6, 2022 11:59
-
-
Save MaikelVeen/21674c68b1cb2aa294fc11787f6ead31 to your computer and use it in GitHub Desktop.
An example of an closure / anonymous function
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
// 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