3 ms·
If you want to `range` over a non-rangeable thing, the idiomatic way to do this is to use an iterator approach: var e elem for nonrangeable.HasNext() {
by rakoo 13y ago
If you want to `range` over a non-rangeable thing, the idiomatic way to do this is to use an iterator approach:
var e elem
for nonrangeable.HasNext() {
e = nonrangeable.Next()
// do stuff with e
}
Coincidentally, that's what the built-in io.Copy [0] does.
(I'm also very biased, but I think this approach fits better with the fact that Go is targeted towards stream processing)
[0] http://golang.org/src/pkg/io/io.go?s=11928:11988#L330 http://golang.org/src/pkg/io/io.go?s=11928:11988#L330