Skip to content

Instantly share code, notes, and snippets.

@kazasiki
Created April 20, 2018 07:23
Show Gist options
  • Save kazasiki/ac5fff37804e9020e11959661b6ea1cd to your computer and use it in GitHub Desktop.
Save kazasiki/ac5fff37804e9020e11959661b6ea1cd to your computer and use it in GitHub Desktop.
範囲型っぽいなにか
package main
import "fmt"
type scope struct {
min, max int
}
func NewScope(min, max int) *scope {
return &scope{min, max}
}
func (s scope) Each() chan int {
c := make(chan int)
go func() {
for i := s.min; i <= s.max; i++ {
c <- i
}
close(c)
}()
return c
}
func main() {
for i := range NewScope(1, 10).Each() {
fmt.Println(i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment