0 votes
in GoLang by
What are function closures?

1 Answer

0 votes
by
Function closures is a function value that references variables from outside its body. The function may access and assign values to the referenced variables.

For example: adder() returns a closure, which is each bound to its own referenced sum variable.

package main

import "fmt"

func adder() func(int) int {

sum := 0

return func(x int) int {

sum += x

return sum

}
...