Open TomOnTime opened 8 years ago
Hi,
Yep, that part of Go could get some improvement. I was thinking about something similar to Python's iterators (with __iter__
and __next__
methods), it shouldn't be that hard to do with generics (generic interfaces might be required to implement it cleanly, though, and we don't have them yet).
Reverse iteration could look like this then: for x = range reverse(s)
A major source of off-by-one errors for me has been that there is no equivalent to the Python "reverse" keyword. Forward loops are simple:
for i := range s
but the reverse isfor i := len(s)-1; i >= 0; i--
.Please consider adding a revrange keyword or something similar.