have icon indicating copy to clipboard operation
have copied to clipboard

Add python-like "reverse range"

Open TomOnTime opened this issue 9 years ago • 1 comments

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 is for i := len(s)-1; i >= 0; i--.

Please consider adding a revrange keyword or something similar.

TomOnTime avatar Oct 03 '16 15:10 TomOnTime

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)

vrok avatar Oct 03 '16 15:10 vrok