Created
March 7, 2020 07:36
-
-
Save SimonAKing/cfef593dab315396c34046285f45876d to your computer and use it in GitHub Desktop.
Generator.go
This file contains 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 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