Last active
November 6, 2020 09:18
-
-
Save foreseaz/d2c9e03fbf7d406584a9de8740afdaa4 to your computer and use it in GitHub Desktop.
Go Patterns
This file contains hidden or 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 fib(n int) chan int { | |
out := make(chan int) | |
go func () { | |
defer close(out) | |
for i, j := 0, 1; i < n; i, j = i + j, i { | |
out <- i | |
} | |
}() | |
return out | |
} | |
func main() { | |
for x := range fib(1000000) { | |
fmt.Println(x) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment