💻 Tech
In Go, you can indicate in the function signature if a channel is receive- or send-only. The trick to remember it is the direction of the arrow. If the arrow is pointing to chan like chan<-, it means it’s send-only. If the arrow is pointing away from chan like <-chan, it means it’s receive-only.
This is helpful if you want to make it clear in your code and also to enforce the direction of the channel. If a channel is used not as intended, the compiler will catch it.
func send(ch chan<- int) {
ch <- 1
}
func receive(ch <-chan int) {
fmt.Println(<-ch)
}