Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shockalotti/5024be3c2a05d49f20a9 to your computer and use it in GitHub Desktop.
Save shockalotti/5024be3c2a05d49f20a9 to your computer and use it in GitHub Desktop.
Go Golang - Closures have access to other local variables
package main
import "fmt"
func main() {
x := 0
increment := func() int {
x++
return x
}
fmt.Println(increment())
fmt.Println(increment())
fmt.Println(increment())
fmt.Println(increment())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment