Created
July 25, 2018 08:20
-
-
Save robertscherbarth/bb0af1e4c9e112cd64f872adeb1132d3 to your computer and use it in GitHub Desktop.
Higher Order functions in golang
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
package main | |
import ( | |
"fmt" | |
) | |
func getIncrementer() func() int { | |
i := -1 | |
return func() int { | |
i = i + 1 | |
return i | |
} | |
} | |
func main() { | |
increment := getIncrementer() | |
fmt.Println(increment()) | |
fmt.Println(increment()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment