Sign in
go
/
website
/
b4564f4a8ce1a51d6c3e3c2571a1122924d525c7
/
.
/
_content
/
tour
/
moretypes
/
function-closures.go
blob: df09995547cc46048d5486c41b2da8c4cdd73a6c [
file
] [
log
] [
blame
]
// +build OMIT
package main
import "fmt"
func adder() func(int) int {
sum := 0
return func(x int) int {
sum += x
return sum
}
}
func main() {
pos, neg := adder(), adder()
for i := 0; i < 10; i++ {
fmt.Println(
pos(i),
neg(-2*i),
)
}
}