Learning Functional Programming in Go
上QQ阅读APP看书,第一时间看更新

Go channels used by the New function

In the itertools.go file, we see that the iterator uses Go channels to range over each element in the collection:

type Iter chan interface{}
func New(els ... interface{}) Iter {
c := make(Iter)
go func () {
for _, el := range els {
c <- el
}
close(c)
}()
return c
}

The New function can be used as follows to take a list of values and turn it into a new iterable collection:

New(3,5,6)