-
Notifications
You must be signed in to change notification settings - Fork 309
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
Laziness of our iterators #791
Comments
About
The most important method is I worry it might result in a slower iterator. @jswrenn @phimuemue What do you think about such pattern/type? |
Similar to #601 but for all our iterators and iterator adaptors.
Laziness reference: https://doc.rust-lang.org/std/iter/index.html#laziness
And I think each iterator struct should have the related
must_use
attribute:#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
#[must_use = "iterators are lazy and do nothing unless consumed"]
Load some items might be unavoidable in some case(?) but surely not all. TODO:
must_use
attributes on adaptors #794Permutations
lazy #793permutations(n)
consumesn
items at definition (so not lazy whenn >= 1
).Combinations
lazy #795combinations(n)
consumesn
items at definition (so not lazy whenn >= 1
).Intersperse[With]
lazy #797intersperse[_with]
both consume 1 item at definition.Product
lazy #800a.cartesian_product(b)
consumes 1 item ofa
at definition.Therefore
iproduct!(i_1, i_2, i_n)
consumes 1 item of the firstn - 1
iterators at definition.CoalesceBy
lazy #801coalesce
,dedup[_by][_with_count]
all consume 1 item at definition.CONTRIBUTING.md
#767 mention laziness for new iterator adaptors and where to test it.tuple_combinations::<T>
consume 1 item per nested iterator at definition ("T::len()" - 1
items so not lazy for(_, _, ...)
).kmerge[_by]
collect all items and consume 1 item of each iterator at definition.Maybe update the documentation of all "eager" adaptors to say that there are "eager":dropping dropping_back sorted_unstable sorted_unstable_by sorted_unstable_by_key sorted sorted_by sorted_by_key sorted_by_cached_key k_smallest k_smallest_by k_smallest_by_key k_largest k_largest_by k_largest_by_key tail
(sodropping[_back]
and methods returningVec[Deque]IntoIter
).It's already good enough, it says it's "eager", or that "it consumes the entire iterator", or that "if collected to a
Vec[Deque]
, is converted without any extra copying or allocation cost".The text was updated successfully, but these errors were encountered: