Skip to content

Instantly share code, notes, and snippets.

@tsonglew
Created November 22, 2017 11:45
Show Gist options
  • Save tsonglew/122e4ba72caf46ba2da37f8b3c921e0d to your computer and use it in GitHub Desktop.
Save tsonglew/122e4ba72caf46ba2da37f8b3c921e0d to your computer and use it in GitHub Desktop.
package main
import "fmt"
func gen(nums ...int) chan int {
out := make(chan int)
go func() {
for _, n := range nums {
out <- n
}
close(out)
}()
return out
}
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() {
for n := range sq(sq(gen(2, 3))) {
fmt.Println(n)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment