Skip to content

Commit

Permalink
Forward more iterator methods (#614)
Browse files Browse the repository at this point in the history
Forwarded some methods to `inner` iterator:

- nth
- collect
- any
- all
- find
- find_map
- count
- last
- position
  • Loading branch information
Andrew authored and jturner314 committed Apr 19, 2019
1 parent 2924f2e commit f566d8c
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/iterators/mod.rs
Expand Up @@ -13,6 +13,7 @@ mod windows;
mod lanes;
pub mod iter;

use std::iter::FromIterator;
use std::marker::PhantomData;
use std::ptr;

Expand Down Expand Up @@ -388,6 +389,54 @@ impl<'a, A, D: Dimension> Iterator for Iter<'a, A, D> {
{
either!(self.inner, iter => iter.fold(init, g))
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
either_mut!(self.inner, iter => iter.nth(n))
}

fn collect<B>(self) -> B
where B: FromIterator<Self::Item>
{
either!(self.inner, iter => iter.collect())
}

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

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

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

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

fn count(self) -> usize {
either!(self.inner, iter => iter.count())
}

fn last(self) -> Option<Self::Item> {
either!(self.inner, iter => iter.last())
}

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

impl<'a, A> DoubleEndedIterator for Iter<'a, A, Ix1> {
Expand Down Expand Up @@ -455,6 +504,54 @@ impl<'a, A, D: Dimension> Iterator for IterMut<'a, A, D> {
{
either!(self.inner, iter => iter.fold(init, g))
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
either_mut!(self.inner, iter => iter.nth(n))
}

fn collect<B>(self) -> B
where B: FromIterator<Self::Item>
{
either!(self.inner, iter => iter.collect())
}

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

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

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

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

fn count(self) -> usize {
either!(self.inner, iter => iter.count())
}

fn last(self) -> Option<Self::Item> {
either!(self.inner, iter => iter.last())
}

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

impl<'a, A> DoubleEndedIterator for IterMut<'a, A, Ix1> {
Expand Down

0 comments on commit f566d8c

Please sign in to comment.