Skip to content

Instantly share code, notes, and snippets.

@StevenACoffman
Created November 4, 2020 19:47
Show Gist options
  • Save StevenACoffman/3c0c3034065593dccabc47e978a1a3df to your computer and use it in GitHub Desktop.
Save StevenACoffman/3c0c3034065593dccabc47e978a1a3df to your computer and use it in GitHub Desktop.
Channels

You can think loosely of channels like pipes for fluid - pour it in one end and out at the other.

By including the arrow <- chan or chan <-, you are achieving three things:

  1. You are making it clear that the parameter is one end of a channel.
  2. You are expressing clearly which end is being supplied.
  3. You are giving more information to the compiler for checking. If the function body tries to use the wrong end of the channel, the compiler can raise an error. These are good reasons to show the channel end whenever possible.
when you see which end is of the channel is it for?
chan <- writing to channel (output channel)
<- chan reading from channel (input channel)
chan read from or write to channel (input/output channel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment