why not unify them when designing them? "for dataIndex, data = range aChannel" looks great.
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The "for k, v = range x" syntax iterates over all entries where x[k] == v. Channels aren't indexable though, so that convention doesn't make sense for them.
-j
---j
Because channel values do not have indices. They are a stream of values and each iteration of the for loop is “the” value.
If you made it with an index that counts up from zero, then you could be creating an iteration loop index that has nothing to do with the value in the channel. You could do that yourself:
dataIndex := 0
for data := range aChannel {
…
dataIndex++
--
why not unify them when designing them? "for dataIndex, data = range aChannel" looks great.
why not unify them when designing them? "for dataIndex, data = range aChannel" looks great.
On Wednesday, July 13, 2016 at 5:10:46 PM UTC+2, T L wrote:why not unify them when designing them? "for dataIndex, data = range aChannel" looks great.A channel:
- has potentially infinite lifetime, which means dataIndex could overflow