【Go】Function closure

Closures exist in many programming languages

The go function is allowed to exist in the form of a closure

A closure is a new function returned inside a function that references a variable outside the function

1
2
3
4
5
6
7
func add() func(int) int {
sum := 0
return func (x int) int {
sum += x
return sum
}
}
Persist in original technology sharing, your support will encourage me to continue to create!