Skip to content

Instantly share code, notes, and snippets.

@npat-efault
Created January 6, 2014 02:11
Show Gist options
  • Save npat-efault/8277123 to your computer and use it in GitHub Desktop.
Save npat-efault/8277123 to your computer and use it in GitHub Desktop.
Fibonacci iterator in Go
// Fibonacci series iterator using closure
package main
import "fmt"
func fibonacci() func() int {
x, y := 0, 1
return func() int {
x, y = y, x + y
return x
}
}
func main() {
fib := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(fib())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment