blob: a4108ee6532f650672252259fed86e8dfed9de42 [file] [log] [blame]
// +build OMIT
package main
import "fmt"
// gen sends the values in nums on the returned channel, then closes it.
func gen(nums ...int) <-chan int {
out := make(chan int)
go func() {
for _, n := range nums {
out <- n
}
close(out)
}()
return out
}
// sq receives values from in, squares them, and sends them on the returned
// channel, until in is closed. Then sq closes the returned channel.
func sq(in <-chan int) <-chan int {
out := make(chan int)
go func() {
for n := range in {
out <- n * n
}
close(out)
}()
return out
}
func main() {
// Set up the pipeline and consume the output.
for n := range sq(sq(gen(2, 3))) {
fmt.Println(n) // 16 then 81
}
}