Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- // fibonacci is a function that returns
- // a function that returns an int.
- func fibonacci() func() int {
- current := 0
- next := 1
- return func() int {
- result := current
- current = next
- next = result + next
- return result
- }
- }
- func main() {
- f := fibonacci()
- for i := 0; i < 10; i++ {
- fmt.Println(f())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement