pub trait IteratorExt: Iterator {
// Required methods
fn consume(self) -> Self
where Self: Sized;
fn drop(self, n: isize) -> Self
where Self: Sized + DoubleEndedIterator;
fn first(self) -> Option<Self::Item>
where Self: Sized;
fn first_result(self) -> RvResult<Self::Item>
where Self: Sized;
fn last_result(self) -> RvResult<Self::Item>
where Self: Sized;
fn single(self) -> RvResult<Self::Item>
where Self: Sized;
fn slice(self, left: isize, right: isize) -> Self
where Self: Sized + Clone + DoubleEndedIterator;
fn some(self) -> bool
where Self: Sized;
}Expand description
Provides extensions for the Iterator trait
Required Methods§
Sourcefn consume(self) -> Selfwhere
Self: Sized,
fn consume(self) -> Selfwhere
Self: Sized,
Consume the entire iterator eagerly up until but not including the last call to get None. Allows caller to then call next and get None.
§Examples
use rivia::prelude::*;
assert_eq!(vec![0, 1, 2].into_iter().consume().next(), None);Sourcefn drop(self, n: isize) -> Selfwhere
Self: Sized + DoubleEndedIterator,
fn drop(self, n: isize) -> Selfwhere
Self: Sized + DoubleEndedIterator,
Drop the first n items if positive from the iterator eagerly and then return the
iterator. Drop the last |n| items if negative from the iterator eagerly and then
return the iterator.
§Examples
use rivia::prelude::*;
assert_iter_eq(vec![1, 2, 3].into_iter().drop(1), vec![2, 3]);
assert_iter_eq(vec![1, 2, 3].into_iter().drop(-1), vec![1, 2]);Sourcefn first_result(self) -> RvResult<Self::Item>where
Self: Sized,
fn first_result(self) -> RvResult<Self::Item>where
Self: Sized,
If the iterator yields at least one element, the first element will be returned, otherwise an error will be returned.
§Examples
use rivia::prelude::*;
assert_eq!((0..10).filter(|&x| x == 2).first().unwrap(), 2);Sourcefn last_result(self) -> RvResult<Self::Item>where
Self: Sized,
fn last_result(self) -> RvResult<Self::Item>where
Self: Sized,
If the iterator yields at least one element, the last element will be returned, otherwise an error will be returned.
§Examples
use rivia::prelude::*;
assert_eq!((0..10).filter(|&x| x == 2).last().unwrap(), 2);Sourcefn single(self) -> RvResult<Self::Item>where
Self: Sized,
fn single(self) -> RvResult<Self::Item>where
Self: Sized,
If the iterator yields a single element, that element will be returned, otherwise an error will be returned.
§Examples
use rivia::prelude::*;
assert_eq!((0..10).filter(|&x| x == 2).single().unwrap(), 2);Sourcefn slice(self, left: isize, right: isize) -> Self
fn slice(self, left: isize, right: isize) -> Self
Slice returns this iterator eagerly to only iterate over the range of elements called out by the given indices. Allows for negative notation.
Note this operation uses count() to determine length which means cost O(n) out of the gate.
§Examples
use rivia::prelude::*;
let mut iter = vec![0, 1, 2].into_iter().slice(0, 0);
assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next(), None);
let mut iter = vec![0, 1, 2].into_iter().slice(-1, -1);
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), None);
let mut iter = vec![0, 1, 2].into_iter().slice(-2, -1);
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), None);