Skip to content

Instantly share code, notes, and snippets.

@FZambia
Last active December 18, 2015 00:59
Show Gist options
  • Save FZambia/5700779 to your computer and use it in GitHub Desktop.
Save FZambia/5700779 to your computer and use it in GitHub Desktop.
my first generator in Go - fibonacci sequence
package main
import "fmt"
func fibgen() func() {
a, b := 0, 1
return func() {
sum := a + b
fmt.Println(sum)
a, b = b, sum
}
}
func main() {
gen := fibgen()
for i := 0; i < 10; i++ {
gen()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment