Created
October 26, 2016 09:55
-
-
Save hsleonis/8b2b7af470d3b6fc7fe5acee6f2e060f to your computer and use it in GitHub Desktop.
Simple closure with GoLang
This file contains hidden or 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 name(s string, m int) func(int) (int, string) { | |
sum := len(s)+m | |
return func(x int) (int, string) { | |
sum += x | |
var val string | |
if val="even"; sum%2==1 { | |
val = "odd" | |
} | |
return sum,val | |
} | |
} | |
func main() { | |
pos:= name("LEO", 5) | |
for i := 0; i < 10; i++ { | |
fmt.Println(pos(i)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment