3 ms·
I think the idea of a standard iterator interface is good, it will allow standard implementations of Map, Filter, and other convenient functional helpers. But
by assbuttbuttass 4y ago
I think the idea of a standard iterator interface is good, it will allow standard implementations of Map, Filter, and other convenient functional helpers.
But I have mixed feelings on the overloading of the "for x := range" syntax. One of the things I like about go is that it's easy to dive into a new code base and understand what's going on. Overloading the range operator means to understand a for loop I need to jump around to understand the iterator implementation.
It's already pretty easy to loop over an iterator, e.g.
for {
x, ok := it.Next()
if !ok {
break
}
...
}
I'm not convinced that overloading range is worth it. But on the other hand, I'm sure I would get used to it fairly quickly
- amscanne 4y agoIt’s actually even simpler, just a one-liner: for x, ok := it.Next(); ok; x, ok = it.Next() { // … }