Skip to content

Instantly share code, notes, and snippets.

@foreseaz
Last active November 6, 2020 09:18
Show Gist options
  • Save foreseaz/d2c9e03fbf7d406584a9de8740afdaa4 to your computer and use it in GitHub Desktop.
Save foreseaz/d2c9e03fbf7d406584a9de8740afdaa4 to your computer and use it in GitHub Desktop.
Go Patterns
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