Skip to content

Instantly share code, notes, and snippets.

@mayra-cabrera
Last active October 25, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayra-cabrera/eb5c0a3441c42d9dbd87 to your computer and use it in GitHub Desktop.
Save mayra-cabrera/eb5c0a3441c42d9dbd87 to your computer and use it in GitHub Desktop.
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
first, second := 0, 1
return func() int{
first, second = second, first + second
return first
}
}
func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment