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

Should the reverse iterators on strings and vectors be removed? #9391

Closed
Kimundi opened this issue Sep 21, 2013 · 2 comments
Closed

Should the reverse iterators on strings and vectors be removed? #9391

Kimundi opened this issue Sep 21, 2013 · 2 comments
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.

Comments

@Kimundi
Copy link
Member

Kimundi commented Sep 21, 2013

Most common iterators also implement DoubleEndedIterator, which means we can turn an Iterator into an reverse Iterator. The replacement would look like this:

"foo".rev_iter()             -> "foo".iter().invert()
"foo".byte_rev_iter()        -> "foo".byte_iter().invert()
"foo".char_offset_rev_iter() -> "foo".char_offset_iter().invert()
"foo".split_rev_iter()       -> "foo".split_iter().invert()
@bluss
Copy link
Member

bluss commented Sep 22, 2013

Fyi, splitn_iter is not a double-ended iterator today, because "split on 'x' 5 times from the front" is not easily reversible. If you change the definition to "split on 'x' 5 times from either end we take elements from", it would be, but that's an inconsistent step away from other double ended iterators.

(On the others, I'm sympathetic. 18 iterator methods is a lot.)

@Kimundi
Copy link
Member Author

Kimundi commented Sep 22, 2013

Ah, didn't realize that. We'd have to keep splitn separate then.

bors added a commit that referenced this issue Nov 26, 2013
This PR removes almost all `_iter` suffixes in various APIs of the codebase that return Iterators, as discussed in #9440.

As a summarize for the intend behind this PR:

- Iterators are the recommended way to provide a potentially lazy list of values, no need to name them painfully verbose. If anything, functions that return a specific container type should have more verbose names.
- We have a static type system, so no need to encode the return value of a constructor function into its name.

Following is a possibly incomplete list of all renamings I performed in the codebase. For a few of them I'm a bit unsure whether the new name still properly expresses their functionality, so feedback would be welcome:

~~~
&str : word_iter()             -> words()
       line_iter()             -> lines()
       any_line_iter()         -> lines_any()
       iter()                  -> chars()
       char_offset_iter()      -> char_indices()
       byte_iter()             -> bytes()
       split_iter()            -> split()
       splitn_iter()           -> splitn()
       split_str_iter()        -> split_str()
       split_terminator_iter() -> split_terminator()
       matches_index_iter()    -> match_indices()
       nfd_iter()              -> nfd_chars()
       nfkd_iter()             -> nfkd_chars()
      
&[T] : split_iter()        -> split()
       splitn_iter()       -> splitn()
       window_iter()       -> windows()
       chunk_iter()        -> chunks()
       permutations_iter() -> permutations()
      
extra:bitv::Bitv :  rev_liter()    -> rev_iter()
                    common_iter()  -> commons()
                    outlier_iter() -> outliers()

extra::treemap::{...} : lower_bound_iter() -> lower_bound()
                        upper_bound_iter() -> upper_bound()
                       
std::trie::{...} : bound_iter()       -> bound()
                   lower_bound_iter() -> lower_bound()
                   upper_bound_iter() -> upper_bound()

rustpkg::package_id::{...} : prefixes_iter() -> prefixes()

std::hashmap::{...} : difference_iter()           -> difference()
                      symmetric_difference_iter() -> symmetric_difference()
                      intersection_iter()         -> intersection()
                      union_iter()                -> union()
                     
std::path::{posix, windows} : component_iter()     -> components()
                              str_component_iter() -> str_components()

... not showing all identical renamings for reverse versions
~~~

---

I'm also planning a few more changes, like removing all unnecessary `_rev` constructors (#9391), or reducing the `split` variants on `&str` to a more versatile and concise system.
@bors bors closed this as completed in 9f484e6 May 1, 2014
Jarcho pushed a commit to Jarcho/rust that referenced this issue Aug 31, 2022
Jarcho pushed a commit to Jarcho/rust that referenced this issue Aug 31, 2022
Fix missing parens in `suboptimal_flops` suggestion

Fixes rust-lang#9391. The problem is simple enough, I didn't check if the same problem occurs elsewhere, though.

changelog: fix missing parenthesis in `suboptimal_flops` suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants