Created
April 20, 2018 07:23
-
-
Save kazasiki/ac5fff37804e9020e11959661b6ea1cd to your computer and use it in GitHub Desktop.
範囲型っぽいなにか
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" | |
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