Skip to content

Instantly share code, notes, and snippets.

@Tomotoes
Created March 7, 2020 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tomotoes/cfef593dab315396c34046285f45876d to your computer and use it in GitHub Desktop.
Save Tomotoes/cfef593dab315396c34046285f45876d to your computer and use it in GitHub Desktop.
Generator.go
package main
import "fmt"
func Iter(start, end int) chan int {
ch := make(chan int)
go func(ch chan int) {
for i := start; i <= end; i++ {
ch <- i
}
close(ch)
}(ch)
return ch
}
func main() {
for num := range Iter(0, 99) {
fmt.Println(num)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment