-
Notifications
You must be signed in to change notification settings - Fork 13.3k
range functions should iterate backwards as well #1817
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
Comments
Is this what you are thinking about? #[doc = "Iterate over the range [`begin`..`end`)"]
fn range(begin: i16, end: i16, it: fn(i16)) {
let i = begin;
if begin < end {
while i < end { it(i); i += 1i16; }
} else {
while i > end { it(i); i -= 1i16; }
}
} Is there a test suite for libcore? |
Yes, that's what I was thinking. The core tests are located in the core crate, near the code they test (marked with the |
Although maybe it makes sense for the reverse range to cover the same numbers, so it would still include the low value, but not the high value. Not sure. I wonder if there's a precedent in another language. |
Would it be a better idea to have an implementation like in Python?
|
Python's |
I would be fine with copying python. |
Ok. I will attach a pull request later today. |
I think a separate rrange function would be safer. One programmer’s reverse range is another’s base case empty range. |
@andreisavu -- are you still working on this? |
No, I'm busy with other things.
|
Ok, then this is up for grabs. |
Fixed as of 982cf90 |
Right now we have a bunch of
range
functions in modint
, etc that all iterate from low to high. It would be convenient if they would detect that the arguments were in high to low order and provide a reverse range. If not, then we needrrange
functions.The text was updated successfully, but these errors were encountered: