Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DhritiShikhar/3e61e849af07d9528ec3b7a667904b44 to your computer and use it in GitHub Desktop.
Save DhritiShikhar/3e61e849af07d9528ec3b7a667904b44 to your computer and use it in GitHub Desktop.
// 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