Created
May 5, 2018 13:45
-
-
Save DhritiShikhar/3e61e849af07d9528ec3b7a667904b44 to your computer and use it in GitHub Desktop.
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
// Golang Closure | |
package main | |
import ( | |
"fmt" | |
) | |
func step1() func() int { | |
i := 0 | |
fmt.Println("it goes inside step1") | |
return func() int { | |
fmt.Println("it goes inside anon func") | |
i++ | |
return i | |
} | |
} | |
func main() { | |
nextStep := step1() | |
fmt.Println(nextStep()) | |
fmt.Println(nextStep()) | |
newStep := step1() | |
fmt.Println(newStep()) | |
fmt.Println(newStep()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment