Channels can connect pipeline stages while each stage keeps a small, deterministic responsibility.

Channel Pipeline

channel_pipeline.go
package main

import "fmt"

func main() {
	var count = 
	inputs := make(chan int)
	outputs := []int{}

	go func() {
		for value := 1; value <= count; value++ {
			inputs <- value
		}
		close(inputs)
	}()

	for value := range inputs {
		outputs = append(outputs, value*value)
	}

	total := 0
	for _, value := range outputs {
		total += value
	}

	fmt.Println("count=", count)
	fmt.Println("outputs=", outputs)
	fmt.Println("total=", total)
}
package main

import "fmt"

func main() {
	var count = 
	inputs := make(chan int)
	outputs := []int{}

	go func() {
		for value := 1; value <= count; value++ {
			inputs <- value
		}
		close(inputs)
	}()

	for value := range inputs {
		outputs = append(outputs, value*value)
	}

	total := 0
	for _, value := range outputs {
		total += value
	}

	fmt.Println("count=", count)
	fmt.Println("outputs=", outputs)
	fmt.Println("total=", total)
}
package main

import "fmt"

func main() {
	var count = 
	inputs := make(chan int)
	outputs := []int{}

	go func() {
		for value := 1; value <= count; value++ {
			inputs <- value
		}
		close(inputs)
	}()

	for value := range inputs {
		outputs = append(outputs, value*value)
	}

	total := 0
	for _, value := range outputs {
		total += value
	}

	fmt.Println("count=", count)
	fmt.Println("outputs=", outputs)
	fmt.Println("total=", total)
}
channel pipeline Start a producer goroutine, transform each value in the main goroutine, and join through channel close semantics.