Create a gist now

Instantly share code, notes, and snippets.

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