This works.
var tick <-chan time.Time = time.Tick(1e8)
However, this does not.
var tick chan time.Time = time.Tick(1e8)
Why do I need a <- in my type declaration for a channel? I thought that <- was for writing to or reading from a channel. Why would it appear in a type?
Channels can have a type indicating whether it is readonly, writeonly or both.
Indicating a channel direction is done with <- as part of the type or omitted for a read/write channel.
So the
<-in<-chan time.Timeis part of the type,and
time.Tick(1e8)returns a read only channel.Read more in the language spec here