-
Notifications
You must be signed in to change notification settings - Fork 13.3k
reverse vs. rev methods on DoubleEndedIterator are confusing #11770
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
I feel like "reverse" is the odd duck here. It's a little surprising that the way you reverse a collection in-place is via a method on its iterator, it seems like it should be on the collection directly. Meanwhile, rev is exactly what I'd expect. |
I don't understand what you're saying. The fn main() {
let mut xs = [1, 2, 3];
let mut ys = [4, 5, 6];
xs.mut_iter().chain(ys.mut_iter()).reverse_();
println!("{:?} {:?}", xs, ys);
} Note that the trailing underscore is a workaround for a compiler bug / language design issue. A generic implementation of a trait causes the name to be reserved on all types if the trait is in scope. |
see also #10632 |
I idly wonder whether one way to deal with issues like this would be via a design heuristic such as "if the same concept can be implemented by both an in-place modification of the receiver and a pure operation that constructs a fresh object, then one should use a method for the in-place modification, and a separate function for the construction." (But this is based on the assumption that people would be less likely to think that a separate function modifies its argument, which may be unfounded.) |
The description of
does just that, so hopefully you see how someone could be confused. Anyways, I'm not saying "get rid of reverse", I'm saying that of the two use cases, |
Why not use |
This has been addressed with the recent rename to |
The
reverse
method is an in-place reversal and therev
method flips the direction of iteration. There has to be a better naming scheme for this.The text was updated successfully, but these errors were encountered: