Created
May 27, 2016 09:49
-
-
Save godfat/c876d2202fe3bb2897e47c5d155c20df to your computer and use it in GitHub Desktop.
the same closure trick in go
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 main() { | |
var a [5]func() int | |
for i:=0; i < 5; i++ { | |
a[i] = func(ii int) func() int { | |
return func() int { | |
return ii | |
} | |
}(i) | |
} | |
for i:=0; i < 5; i++ { | |
fmt.Println(a[i]()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment