Closure in Golang

package mainimport "fmt"// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
first := 0
second := 1
f := func() int {
sum := first + second
first, second = second, sum
return sum
}
return f
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simplify Complexity

Simplify Complexity

422 Followers

Golang, Distributed Systems, File Systems, Python, C/C++, Linux