Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python-like "reverse range" #10

Open
TomOnTime opened this issue Oct 3, 2016 · 1 comment
Open

Add python-like "reverse range" #10

TomOnTime opened this issue Oct 3, 2016 · 1 comment

Comments

@TomOnTime
Copy link

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.

@vrok
Copy link
Owner

vrok commented Oct 3, 2016

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants