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
Add .get(range)
#891
base: master
Are you sure you want to change the base?
Add .get(range)
#891
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #891 +/- ##
==========================================
+ Coverage 94.38% 94.55% +0.16%
==========================================
Files 48 49 +1
Lines 6665 6945 +280
==========================================
+ Hits 6291 6567 +276
- Misses 374 378 +4 ☔ View full report in Codecov by Sentry. |
97c74c3
to
d518cae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these are just things to ponder that might not need changing, but I think at least the overflow thing should be tweaked.
/// Returns an iterator over a subsection of the iterator. | ||
/// | ||
/// See [`Itertools::get`] for more information. | ||
pub fn get<I, R>(iter: I, index: R) -> R::Output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very generic name to have as a top-level method. Does it really pull its weight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name is appropriate — it 'gets' elements from the iterator. We use get
for consistency with [T]::get
, and match its API as closely as possible. There's little risk of conflict, since slices do not directly implement Iterator
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Itertools
trait, I understand.
But it's also pulled in as a function (https://github.com/rust-itertools/itertools/pull/891/files#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R157). I guess it's unlikely to matter unless people are doing use itertools::*;
, which is already discouraged, but as a thing not scoped to an impl it seems surprising.
(But you can feel free to "won't fix" this -- I don't feel that strongly about it.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah fair enough, we don't really need to make the free function get
public.
8831e7d
to
b891b69
Compare
I rebased on master and added 4 commits:
And removed |
Co-Authored-By: wod3 <17980899+wod3@users.noreply.github.com>
Co-Authored-By: TrolledWoods <26680270+trolledwoods@users.noreply.github.com>
Fix my own review. Update docs. Fix a warning with `#[cfg(doc)]`. Use public path `traits::IteratorIndex` instead of private path `iter_index::IteratorIndex`.
As we should, I checked it can't pass without `let _ =`.
`RangeInclusive::is_empty` (rust 1.47+) is in conflict with our MSRV (1.43.1) so we can't use it yet. The unspecified behavior is documented in `Itertools::get` so we simply remove this.
Unless there is a reason to prefer `Take<Skip>` over `Skip<Take>`?!
3f53078
to
6477ac0
Compare
A `use itertools::*;` might conflict with such a general function name.
6477ac0
to
de08253
Compare
Closes #447.
So much changes happened since this work was initiated that rebase on top of master seems nothing less than a nightmare to me (I know, I tried). I therefore looked at the git differences, committed those (after formatting) and credited @wod3 and @TrolledWoods for their respective commits. Then I fixed my own review and a bit more.
I thought I would additionally implement
IteratorIndex
forEither<range, range>
(andBox<dyn range>
but I could not) but doing so would later result in a nasty breaking change if this was removed after an eventual inclusion toIterator
.Details about either