Trait internal_iterator::InternalIterator[][src]

#[must_use = "internal iterators are lazy and do nothing unless consumed"]pub trait InternalIterator: Sized {
    type Item;
    fn find_map<R, F>(self, f: F) -> Option<R>
    where
        F: FnMut(Self::Item) -> Option<R>
; fn all<F>(self, f: F) -> bool
    where
        F: FnMut(Self::Item) -> bool
, { ... }
fn any<F>(self, f: F) -> bool
    where
        F: FnMut(Self::Item) -> bool
, { ... }
fn chain<U>(
        self,
        other: U
    ) -> Chain<Self, <U as IntoInternalIterator>::IntoIter>
    where
        U: IntoInternalIterator<Item = Self::Item>
, { ... }
fn cloned<'a, T: 'a>(self) -> Cloned<Self>
    where
        Self: InternalIterator<Item = &'a T>,
        T: Clone
, { ... }
fn collect<B>(self) -> B
    where
        B: FromInternalIterator<Self::Item>
, { ... }
fn copied<'a, T: 'a>(self) -> Copied<Self>
    where
        Self: InternalIterator<Item = &'a T>,
        T: Copy
, { ... }
fn count(self) -> usize { ... }
fn enumerate(self) -> Enumerate<Self> { ... }
fn filter<P>(self, predicate: P) -> Filter<Self, P>
    where
        P: FnMut(&Self::Item) -> bool
, { ... }
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
    where
        F: FnMut(Self::Item) -> Option<T>
, { ... }
fn find<F>(self, f: F) -> Option<Self::Item>
    where
        F: FnMut(&Self::Item) -> bool
, { ... }
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F>
    where
        F: FnMut(Self::Item) -> U,
        U: IntoInternalIterator
, { ... }
fn for_each<F>(self, f: F)
    where
        F: FnMut(Self::Item)
, { ... }
fn inspect<F>(self, f: F) -> Inspect<Self, F>
    where
        F: FnMut(&Self::Item)
, { ... }
fn last(self) -> Option<Self::Item> { ... }
fn map<F, T>(self, f: F) -> Map<Self, F>
    where
        F: FnMut(Self::Item) -> T
, { ... }
fn max(self) -> Option<Self::Item>
    where
        Self::Item: Ord
, { ... }
fn max_by<F>(self, compare: F) -> Option<Self::Item>
    where
        F: FnMut(&Self::Item, &Self::Item) -> Ordering
, { ... }
fn min(self) -> Option<Self::Item>
    where
        Self::Item: Ord
, { ... }
fn min_by<F>(self, compare: F) -> Option<Self::Item>
    where
        F: FnMut(&Self::Item, &Self::Item) -> Ordering
, { ... }
fn next(self) -> Option<Self::Item> { ... }
fn nth(self, n: usize) -> Option<Self::Item> { ... }
fn position<F>(self, f: F) -> Option<usize>
    where
        F: FnMut(Self::Item) -> bool
, { ... }
fn skip(self, n: usize) -> Skip<Self> { ... }
fn take(self, n: usize) -> Take<Self> { ... } }

Internal iterator over a collection.

Associated Types

type Item[src]

Type of items yielded by the iterator.

Loading content...

Required methods

fn find_map<R, F>(self, f: F) -> Option<R> where
    F: FnMut(Self::Item) -> Option<R>, 
[src]

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));
Loading content...

Provided methods

fn all<F>(self, f: F) -> bool where
    F: FnMut(Self::Item) -> bool
[src]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

Run the closure on each element.

fn inspect<F>(self, f: F) -> Inspect<Self, F> where
    F: FnMut(&Self::Item), 
[src]

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]

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]

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]

Returns the maximum element of an iterator using a custom comparer function.

fn min(self) -> Option<Self::Item> where
    Self::Item: Ord
[src]

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]

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 nth 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]

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]);
Loading content...

Implementors

impl<'a, I, T: 'a> InternalIterator for Cloned<I> where
    I: InternalIterator<Item = &'a T>,
    T: Clone
[src]

type Item = T

impl<'a, I, T: 'a> InternalIterator for Copied<I> where
    I: InternalIterator<Item = &'a T>,
    T: Copy
[src]

type Item = T

impl<A, B> InternalIterator for Chain<A, B> where
    A: InternalIterator,
    B: InternalIterator<Item = A::Item>, 
[src]

type Item = A::Item

impl<I> InternalIterator for Enumerate<I> where
    I: InternalIterator
[src]

type Item = (usize, I::Item)

impl<I> InternalIterator for Internal<I> where
    I: Iterator
[src]

type Item = I::Item

impl<I> InternalIterator for Skip<I> where
    I: InternalIterator
[src]

type Item = I::Item

impl<I> InternalIterator for Take<I> where
    I: InternalIterator
[src]

type Item = I::Item

impl<I, F> InternalIterator for Filter<I, F> where
    I: InternalIterator,
    F: FnMut(&I::Item) -> bool
[src]

type Item = I::Item

impl<I, F> InternalIterator for Inspect<I, F> where
    I: InternalIterator,
    F: FnMut(&I::Item), 
[src]

type Item = I::Item

impl<I, F, T> InternalIterator for FilterMap<I, F> where
    I: InternalIterator,
    F: FnMut(I::Item) -> Option<T>, 
[src]

type Item = T

impl<I, F, T> InternalIterator for Map<I, F> where
    I: InternalIterator,
    F: FnMut(I::Item) -> T, 
[src]

type Item = T

impl<I, F, T, U> InternalIterator for FlatMap<I, F> where
    I: InternalIterator,
    F: FnMut(I::Item) -> U,
    U: IntoInternalIterator<Item = T>, 
[src]

type Item = T

Loading content...