Created
February 28, 2020 09:05
-
-
Save PeteGabriel/3a28770ddaad5a626b1215ca9b508fa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
naturals := make(chan int) | |
squares := make(chan int) | |
//Counter | |
//implicit conversion | |
go counter(naturals) | |
//Squarer | |
//implicit conversion | |
go square(naturals, squares) | |
for s := range squares { | |
fmt.Println(s) | |
} | |
} | |
func counter(into chan<- int){ | |
for x := 0; x < 10; x++ { | |
into <- x | |
} | |
close(into) | |
} | |
//from = receive-only channel of int | |
//into = send-only channel of int | |
func square(from <-chan int, into chan<- int) { | |
for x := range from { | |
into <- x * x | |
} | |
close(into) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment