Golang Fibonacci Closure Exercise
A sample solution for the Golang exercise to write a Fibonacci closure function.
package main //Covers "Exercise: Fibonacci closure" import "fmt" // fibonacci is a function that returns // a function (i.e. a closure) that returns an int. func fibonacci() func() int { a := 0 b := 1 return func() int { c := a a = b b += c return c } } func main() { f := fibonacci() for i := 0; i < 10; i++ { fmt.Println(f()) } }

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Download this code in plain text format here