Skip to content

Commit

Permalink
Merge pull request #71 from cuviper/iter-more
Browse files Browse the repository at this point in the history
Expand iterator coverage
  • Loading branch information
cuviper authored Jun 28, 2022
2 parents fbbadd0 + 366fa77 commit 26a6dc7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,13 @@ where
for_both!(self, inner => inner.fold(init, f))
}

fn for_each<F>(self, f: F)
where
F: FnMut(Self::Item),
{
for_both!(self, inner => inner.for_each(f))
}

fn count(self) -> usize {
for_both!(self, inner => inner.count())
}
Expand All @@ -924,12 +931,48 @@ where
for_both!(self, inner => inner.collect())
}

fn partition<B, F>(self, f: F) -> (B, B)
where
B: Default + Extend<Self::Item>,
F: FnMut(&Self::Item) -> bool,
{
for_both!(self, inner => inner.partition(f))
}

fn all<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool,
{
for_both!(*self, ref mut inner => inner.all(f))
}

fn any<F>(&mut self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool,
{
for_both!(*self, ref mut inner => inner.any(f))
}

fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
for_both!(*self, ref mut inner => inner.find(predicate))
}

fn find_map<B, F>(&mut self, f: F) -> Option<B>
where
F: FnMut(Self::Item) -> Option<B>,
{
for_both!(*self, ref mut inner => inner.find_map(f))
}

fn position<P>(&mut self, predicate: P) -> Option<usize>
where
P: FnMut(Self::Item) -> bool,
{
for_both!(*self, ref mut inner => inner.position(predicate))
}
}

impl<L, R> DoubleEndedIterator for Either<L, R>
Expand All @@ -952,6 +995,13 @@ where
{
for_both!(self, inner => inner.rfold(init, f))
}

fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
for_both!(*self, ref mut inner => inner.rfind(predicate))
}
}

impl<L, R> ExactSizeIterator for Either<L, R>
Expand All @@ -964,6 +1014,13 @@ where
}
}

impl<L, R> iter::FusedIterator for Either<L, R>
where
L: iter::FusedIterator,
R: iter::FusedIterator<Item = L::Item>,
{
}

#[cfg(any(test, feature = "use_std"))]
/// `Either<L, R>` implements `Read` if both `L` and `R` do.
///
Expand Down

0 comments on commit 26a6dc7

Please sign in to comment.