Skip to content

Instantly share code, notes, and snippets.

@meysampg
Last active May 3, 2019 08:34
Show Gist options
  • Save meysampg/0c2e13717d2bd8411712d1e72693ea74 to your computer and use it in GitHub Desktop.
Save meysampg/0c2e13717d2bd8411712d1e72693ea74 to your computer and use it in GitHub Desktop.
A usage of encapsulation of a clousre for Saman
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