Last active
May 3, 2019 08:34
-
-
Save meysampg/0c2e13717d2bd8411712d1e72693ea74 to your computer and use it in GitHub Desktop.
A usage of encapsulation of a clousre for Saman
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 main() { | |
// this is a function which accept an int and return a function which accept an int and return an int :D | |
var add func(int) func(int) int = func(n int) func(int) int { | |
return func(a int) int { | |
return a + n | |
} | |
} | |
add5 := add(5) | |
fmt.Println(add5(4)) | |
add10 := add(10) | |
fmt.Println(add10(3)) | |
} | |
// meysampg@freedom:~/www/test/closure-go | |
// $ go build main.go | |
// | |
// meysampg@freedom:~/www/test/closure-go | |
// $ ./main | |
// 9 | |
// 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment