Trait internal_iterator::InternalIterator [−][src]
Internal iterator over a collection.
Associated Types
Loading content...Required methods
fn find_map<R, F>(self, f: F) -> Option<R> where
F: FnMut(Self::Item) -> Option<R>,
[src]
F: FnMut(Self::Item) -> Option<R>,
Applies function to the elements of iterator and returns the first non-none result.
let a = ["lol", "two", "NaN", "4", "5"]; let parsed = a .iter() .into_internal() .find_map(|x| x.parse().ok()); assert_eq!(parsed, Some(4));
Provided methods
fn all<F>(self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
[src]
F: FnMut(Self::Item) -> bool,
Tests if every element of the iterator matches the predicate.
let a = [1, 2, 3]; assert!(a.iter().into_internal().all(|&x| x > 0)); assert!(!a.iter().into_internal().all(|&x| x < 2));
fn any<F>(self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
[src]
F: FnMut(Self::Item) -> bool,
Tests if any element of the iterator matches the predicate.
let a = [1, 2, 3]; assert!(a.iter().into_internal().any(|&x| x == 2)); assert!(!a.iter().into_internal().any(|&x| x > 5));
fn chain<U>(
self,
other: U
) -> Chain<Self, <U as IntoInternalIterator>::IntoIter> where
U: IntoInternalIterator<Item = Self::Item>,
[src]
self,
other: U
) -> Chain<Self, <U as IntoInternalIterator>::IntoIter> where
U: IntoInternalIterator<Item = Self::Item>,
Takes two iterators and returns an iterator that first iterates over the elements of the first iterator, and then over the second one.
let a1 = [1, 2, 3]; let a2 = [4, 5, 6]; let chained = a1.iter().into_internal() .chain(a2.iter().into_internal()) .collect::<Vec<_>>(); assert_eq!(chained, vec![&1, &2, &3, &4, &5, &6]);
fn cloned<'a, T: 'a>(self) -> Cloned<Self> where
Self: InternalIterator<Item = &'a T>,
T: Clone,
[src]
Self: InternalIterator<Item = &'a T>,
T: Clone,
Creates an iterator yields cloned elements of the original iterator.
let a = [1, 2, 3]; let cloned = a.iter().into_internal().cloned().collect::<Vec<_>>(); assert_eq!(cloned, vec![1, 2, 3]);
fn collect<B>(self) -> B where
B: FromInternalIterator<Self::Item>,
[src]
B: FromInternalIterator<Self::Item>,
Transforms the iterator into a collection.
let a = [1, 2, 3]; let doubled = a .iter() .into_internal() .map(|&x| x * 2) .collect::<Vec<_>>(); assert_eq!(doubled, vec![2, 4, 6]);
fn copied<'a, T: 'a>(self) -> Copied<Self> where
Self: InternalIterator<Item = &'a T>,
T: Copy,
[src]
Self: InternalIterator<Item = &'a T>,
T: Copy,
Creates an iterator yields copied elements of the original iterator.
let a = [1, 2, 3]; let cloned = a.iter().into_internal().copied().collect::<Vec<_>>(); assert_eq!(cloned, vec![1, 2, 3]);
fn count(self) -> usize
[src]
Returns the number of elements yielded by the iterator.
let a = [1, 2, 3]; assert_eq!(a.iter().into_internal().count(), 3);
fn enumerate(self) -> Enumerate<Self>
[src]
Creates an iterator that adds the index to every value of the original iterator.
let a = ['a', 'b', 'c']; let enumerated = a.iter().into_internal().enumerate().collect::<Vec<_>>(); assert_eq!(enumerated, vec![(0, &'a'), (1, &'b'), (2, &'c')]);
fn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]
P: FnMut(&Self::Item) -> bool,
Creates an iterator which only yields elements matching the predicate.
let a = [0i32, 1, 2]; let positive = a.iter().into_internal().filter(|x| x.is_positive()).collect::<Vec<_>>(); assert_eq!(positive, vec![&1, &2]);
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<T>,
[src]
F: FnMut(Self::Item) -> Option<T>,
A combination of InternalIterator::filter
and
InternalIterator::map
.
let a = ["1", "two", "NaN", "four", "5"]; let parsed: Vec<_> = a .iter() .into_internal() .filter_map(|x| x.parse::<i32>().ok()) .collect(); assert_eq!(parsed, vec![1, 5]);
fn find<F>(self, f: F) -> Option<Self::Item> where
F: FnMut(&Self::Item) -> bool,
[src]
F: FnMut(&Self::Item) -> bool,
Returns the first element of the iterator that matches the predicate.
let a = [1, 2, 3]; assert_eq!(a.iter().into_internal().find(|&&x| x == 2), Some(&2)); assert_eq!(a.iter().into_internal().find(|&&x| x == 5), None);
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F> where
F: FnMut(Self::Item) -> U,
U: IntoInternalIterator,
[src]
F: FnMut(Self::Item) -> U,
U: IntoInternalIterator,
Creates and iterator which maps over the elements and flattens the resulting structure.
The provided closure is expected to return a type implementing
IntoInternalIterator
. The usual types that work with
std::iter::Iterator::flat_map
don't work here, so you will need to
use IteratorExt::into_internal
to use regular iterators with this
function.
let a = [1, 2, 3]; let mapped = a.iter() .into_internal() .flat_map(|&x| vec![x * 10 + 2, x * 10 + 3] .into_iter() .into_internal()) .collect::<Vec<_>>(); assert_eq!(mapped, vec![12, 13, 22, 23, 32, 33]);
fn for_each<F>(self, f: F) where
F: FnMut(Self::Item),
[src]
F: FnMut(Self::Item),
Run the closure on each element.
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
[src]
F: FnMut(&Self::Item),
Run the closure on each element, while passing that element on.
This can be used to inspect the values passed through the iterator while not modifying the rest of the iterator pipeline.
let a = [1, 4, 6, 3, 2]; let v = a.iter() .into_internal() .filter(|&x| x % 2 == 0) .inspect(|x| println!("item: {}", x)) .map(|x| x / 2) .collect::<Vec<_>>(); assert_eq!(v, vec![2, 3, 1]); // also prints to stdout: // item: 4 // item: 6 // item: 2
fn last(self) -> Option<Self::Item>
[src]
Returns the last element.
let a = [1, 2, 3]; assert_eq!(a.iter().into_internal().last(), Some(&3)); let a = [1, 2, 3, 4, 5]; assert_eq!(a.iter().into_internal().last(), Some(&5));
fn map<F, T>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> T,
[src]
F: FnMut(Self::Item) -> T,
Transform each element in the iterator.
let a = [1, 2, 3]; let doubled = a .iter() .into_internal() .map(|&x| x * 2) .collect::<Vec<_>>(); assert_eq!(doubled, vec![2, 4, 6]);
fn max(self) -> Option<Self::Item> where
Self::Item: Ord,
[src]
Self::Item: Ord,
Returns the maximum element of an iterator.
let a = [1, 2, 3]; let b: Vec<u32> = Vec::new(); assert_eq!(a.iter().into_internal().max(), Some(&3)); assert_eq!(b.iter().into_internal().max(), None);
fn max_by<F>(self, compare: F) -> Option<Self::Item> where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
[src]
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
Returns the maximum element of an iterator using a custom comparer function.
fn min(self) -> Option<Self::Item> where
Self::Item: Ord,
[src]
Self::Item: Ord,
Returns the minimum element of an iterator.
let a = [1, 2, 3]; let b: Vec<u32> = Vec::new(); assert_eq!(a.iter().into_internal().min(), Some(&1)); assert_eq!(b.iter().into_internal().min(), None);
fn min_by<F>(self, compare: F) -> Option<Self::Item> where
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
[src]
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
Returns the minimum element of an iterator using a custom comparer function.
fn next(self) -> Option<Self::Item>
[src]
Returns the first element of the iterator.
Note that unlike Iterator::next
, this method consumes the iterator.
It is really only useful for getting the first element in the iterator,
and is called next
just for api similarity with regular iterators.
let a = [1, 2, 3]; assert_eq!(a.iter().into_internal().next(), Some(&1));
fn nth(self, n: usize) -> Option<Self::Item>
[src]
Returns the n
th element of the iterator.
let a = [1, 2, 3]; assert_eq!(a.iter().into_internal().nth(1), Some(&2));
fn position<F>(self, f: F) -> Option<usize> where
F: FnMut(Self::Item) -> bool,
[src]
F: FnMut(Self::Item) -> bool,
Returns the index of the first element matching the predicate.
let a = [1, 2, 3]; assert_eq!(a.iter().into_internal().position(|&x| x == 2), Some(1)); assert_eq!(a.iter().into_internal().position(|&x| x == 5), None);
fn skip(self, n: usize) -> Skip<Self>
[src]
Skip first n
elements of the iterator.
let a = [1, 2, 3, 4]; let v = a.iter().into_internal().skip(2).collect::<Vec<_>>(); assert_eq!(v, vec![&3, &4]);
fn take(self, n: usize) -> Take<Self>
[src]
Take first n
elements of the iterator, disregarding the rest.
let a = [1, 2, 3, 4]; let v = a.iter().into_internal().take(2).collect::<Vec<_>>(); assert_eq!(v, vec![&1, &2]);
Implementors
impl<'a, I, T: 'a> InternalIterator for Cloned<I> where
I: InternalIterator<Item = &'a T>,
T: Clone,
[src]
I: InternalIterator<Item = &'a T>,
T: Clone,
type Item = T
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<'a, I, T: 'a> InternalIterator for Copied<I> where
I: InternalIterator<Item = &'a T>,
T: Copy,
[src]
I: InternalIterator<Item = &'a T>,
T: Copy,
type Item = T
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<A, B> InternalIterator for Chain<A, B> where
A: InternalIterator,
B: InternalIterator<Item = A::Item>,
[src]
A: InternalIterator,
B: InternalIterator<Item = A::Item>,
type Item = A::Item
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I> InternalIterator for Enumerate<I> where
I: InternalIterator,
[src]
I: InternalIterator,
type Item = (usize, I::Item)
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I> InternalIterator for Internal<I> where
I: Iterator,
[src]
I: Iterator,
type Item = I::Item
fn find_map<T, F>(self, consumer: F) -> Option<T> where
F: FnMut(Self::Item) -> Option<T>,
[src]
F: FnMut(Self::Item) -> Option<T>,
impl<I> InternalIterator for Skip<I> where
I: InternalIterator,
[src]
I: InternalIterator,
type Item = I::Item
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I> InternalIterator for Take<I> where
I: InternalIterator,
[src]
I: InternalIterator,
type Item = I::Item
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I, F> InternalIterator for Filter<I, F> where
I: InternalIterator,
F: FnMut(&I::Item) -> bool,
[src]
I: InternalIterator,
F: FnMut(&I::Item) -> bool,
type Item = I::Item
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I, F> InternalIterator for Inspect<I, F> where
I: InternalIterator,
F: FnMut(&I::Item),
[src]
I: InternalIterator,
F: FnMut(&I::Item),
type Item = I::Item
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I, F, T> InternalIterator for FilterMap<I, F> where
I: InternalIterator,
F: FnMut(I::Item) -> Option<T>,
[src]
I: InternalIterator,
F: FnMut(I::Item) -> Option<T>,
type Item = T
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I, F, T> InternalIterator for Map<I, F> where
I: InternalIterator,
F: FnMut(I::Item) -> T,
[src]
I: InternalIterator,
F: FnMut(I::Item) -> T,
type Item = T
fn find_map<R, C>(self, consumer: C) -> Option<R> where
C: FnMut(Self::Item) -> Option<R>,
[src]
C: FnMut(Self::Item) -> Option<R>,
impl<I, F, T, U> InternalIterator for FlatMap<I, F> where
I: InternalIterator,
F: FnMut(I::Item) -> U,
U: IntoInternalIterator<Item = T>,
[src]
I: InternalIterator,
F: FnMut(I::Item) -> U,
U: IntoInternalIterator<Item = T>,