-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Consider removing the _iter
suffixes on specialized Iterator constructors
#9440
Comments
I am totally in favor of this. |
I suppose I should elaborate a bit more. I personally don't like the It could be difficult in that If we do push forward with this, I think that other modules in libstd/extra should be checked to ensure that they adhere to this same convention, which is basically: "Does it make sense without |
@alexcrichton Right, the idiomatic way should be to offer an lazy evaluating |
👍 I'd almost say that |
Could we always return an iterator where we return a list today? |
It will rarely be less efficient, because the iterator's The only case I can think of where there's an efficiency issue is when you're replacing recursive traversals with an iterator managing a stack. The reason simply being that the iterator is usually going to have to allocate the stack, but if it can be done up-front then it will be cheaper than recursion. |
@ thestinger: Thanks. Then i suggest porting everything to iterators. A On second thought, |
I think Regarding |
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.
This got solved by #10622 |
The names tend to become increasingly long, and if there is no alternative way it seems silly to add to the name. The
_iter
suffix can still be used for cases where an operation is also implemented in a non-iterator way, or where no better name can be found.For example, the iterator constructors for
StrSlice
would improve greatly from this:The text was updated successfully, but these errors were encountered: