Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Created October 26, 2016 09:55
Show Gist options
  • Save hsleonis/8b2b7af470d3b6fc7fe5acee6f2e060f to your computer and use it in GitHub Desktop.
Save hsleonis/8b2b7af470d3b6fc7fe5acee6f2e060f to your computer and use it in GitHub Desktop.
Simple closure with GoLang
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