Skip to content

Rename Iterators invert() method to something shorter, like flip() #10632

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

Closed
Kimundi opened this issue Nov 24, 2013 · 16 comments
Closed

Rename Iterators invert() method to something shorter, like flip() #10632

Kimundi opened this issue Nov 24, 2013 · 16 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@Kimundi
Copy link
Member

Kimundi commented Nov 24, 2013

The docs for it already read as "Flip the direction of the iterator", and it's a shorter name.

The length, at the very least, becomes important if we decide to do something like #9391, because then using invert would become the common way to iterater over values in reverse. Compare:

for c in "abc".chars().invert() {
    // c, b, a
}
for c in "abc".chars().flip() {
    // c, b, a
}

Imo, the meaning also becomes marginally more clear that way.

@dredozubov
Copy link

If we do this, we should rename std::iter::Invert to std::iter::Flip. Not sure it is worth doing though. invert sounds pretty straightforward. flip sounds pretty ruby-ish though(nevermind the pun, i actually like the name).

@Kimundi
Copy link
Member Author

Kimundi commented Nov 25, 2013

Sure, the type names will be adjusted to. I personally think invert is a more confusing name than flip though.

@LeoTestard
Copy link
Contributor

Why not something like .rev() ? It means reverse, which explains pretty well what it does (reverse), it looks like the old name (rev_iter), and it sounds like Caml's List.rev or others, and it is pretty short.

@thestinger
Copy link
Contributor

I would expect reverse to reverse the container in-place, like the current implementation on a DoubleEndedIterator of &mut T does.

@LeoTestard
Copy link
Contributor

I meant a .rev() method on the iterator, not on the container itself. I don't think this would be incompatible with a reverse method on the container that would reverse it in-place, but maybe others may find this confusing.

@Kimundi
Copy link
Member Author

Kimundi commented Nov 25, 2013

@LeoTestard reverse is a bad name because this method does not reverse the iterator. :P

A double ended iterator has two ends, and iterating with for just takes values from the front.
invert/flip simply swaps those ends, which means iterating over it from the front would now yield values in reverse order, but there is no actual reversing going on.

@lilyball
Copy link
Contributor

lilyball commented Dec 2, 2013

I prefer the name invert(). It just seems slightly clearer than flip().

@wting
Copy link
Contributor

wting commented Jan 12, 2014

I like flip() since it's shorter and the same name / behavior as Haskell's flip().

@kud1ing
Copy link

kud1ing commented Jan 20, 2014

@wting: flip is for function arguments, Haskell's reverse would be the analogon for iterators.

@thestinger
Copy link
Contributor

There's already a reverse and it acts in-place though.

@kud1ing
Copy link

kud1ing commented Jan 20, 2014

A better name for the in-place version could be revert.
"Reverse" could be an adjective/noun ("give me the reverse"), while "revert" is only a verb: "revert this (in-place)".

@kud1ing
Copy link

kud1ing commented Jan 20, 2014

  • C++: reverse_iterator, std::list::reverse (in-place),
  • Common Lisp: reverse
  • Haskell: reverse
  • Python: reversed, reverse (in-place),
  • Ruby: reverse, reverse! (in-place)

@mankyKitty
Copy link
Contributor

Should it perhaps be something like flip_iter_direction, or flip_iter since it's not reversing the list, it's changing the direction that that iterator is moving on that list.. Or at least as I understand it.

@liigo
Copy link
Contributor

liigo commented Jan 21, 2014

+1 for .rev()

@wting
Copy link
Contributor

wting commented Jan 21, 2014

@kud1ing: Thanks for the correction and the multi-language comparison.

My vote is for .rev() for consistency with .rev_iter() and other languages.

bors added a commit that referenced this issue Jan 24, 2014
…632, r=alexcrichton

Renamed the ```invert()``` function in ```iter.rs``` to ```flip()```, from #10632 

Also renamed the ```Invert<T>``` type to ```Flip<T>```.

Some related code comments changed. Documentation that I could find has
been updated, and all the instances I could locate where the
function/type were called have been updated as well.

This is my first contribution to Rust! Apologies in advance if I've snarfed the 
PR process, I'm not used to rebase.

I initially had issues with the ```codegen``` section of the tests failing, however
the ```make check``` process is not reporting any failures at this time. I think
that was a local env issue more than me facerolling my changes. :)
@thestinger
Copy link
Contributor

bf9c255

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 13, 2024
Add `needless_maybe_sized` lint

changelog: new lint: [`needless_maybe_sized`]

Closes rust-lang#10600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

9 participants