Last active
December 18, 2015 00:59
-
-
Save FZambia/5700779 to your computer and use it in GitHub Desktop.
my first generator in Go - fibonacci sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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