Skip to content

Instantly share code, notes, and snippets.

@tylertreat
Created May 18, 2015 05:41
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 tylertreat/a9144ecf0314611833a1 to your computer and use it in GitHub Desktop.
Save tylertreat/a9144ecf0314611833a1 to your computer and use it in GitHub Desktop.
type IntContainer []int
func (i IntContainer) Iterator() <-chan int {
ch := make(chan int)
go func() {
for _, val := range i {
ch <- val
}
close(ch)
}()
return ch
}
func main() {
c := IntContainer([]int{1, 2, 3, 4, 5})
for x := range c.Iterator() {
println(x)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment