Skip to content

Instantly share code, notes, and snippets.

@williamlsh
Last active November 10, 2018 10:06
Show Gist options
  • Save williamlsh/78a739ae44b75c38cd24edc1fc421ebb to your computer and use it in GitHub Desktop.
Save williamlsh/78a739ae44b75c38cd24edc1fc421ebb to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
f := fibonacci()
fmt.Println(f())
}
func fibonacci() func()int {
pre, cur := 0, 1
return func() int {
pre, cur = cur, pre+cur
return cur
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment