[][src]Trait fungus::core::IteratorExt

pub trait IteratorExt: Iterator {
    pub fn consume(self) -> Self
    where
        Self: Sized
;
pub fn drop(self, n: isize) -> Self
    where
        Self: Sized,
        Self: DoubleEndedIterator
;
pub fn first(self) -> Option<Self::Item>
    where
        Self: Sized
;
pub fn first_result(self) -> FuResult<Self::Item>
    where
        Self: Sized
;
pub fn last_result(self) -> FuResult<Self::Item>
    where
        Self: Sized
;
pub fn single(self) -> FuResult<Self::Item>
    where
        Self: Sized
;
pub fn slice(self, left: isize, right: isize) -> Self
    where
        Self: Sized,
        Self: Clone,
        Self: DoubleEndedIterator
;
pub fn some(self) -> bool
    where
        Self: Sized
; }

Iterator adaptors to simplify some operations

Required methods

pub fn consume(self) -> Self where
    Self: Sized
[src]

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 fungus::core::*;

assert_eq!(vec![0, 1, 2].into_iter().consume().next(), None);

pub fn drop(self, n: isize) -> Self where
    Self: Sized,
    Self: DoubleEndedIterator
[src]

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 fungus::core::*;

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]);

pub fn first(self) -> Option<Self::Item> where
    Self: Sized
[src]

Returns the first element of the iterator. Alias to nth(0).

first() will return None if n is greater than or equal to the length of the iterator.

Examples

use fungus::core::*;

assert_eq!((0..10).filter(|&x| x == 2).first().unwrap(), 2);

pub fn first_result(self) -> FuResult<Self::Item> where
    Self: Sized
[src]

If the iterator yields at least one element, the first element will be returned, otherwise an error will be returned.

Examples

use fungus::core::*;

assert_eq!((0..10).filter(|&x| x == 2).first().unwrap(), 2);

pub fn last_result(self) -> FuResult<Self::Item> where
    Self: Sized
[src]

If the iterator yields at least one element, the last element will be returned, otherwise an error will be returned.

Examples

use fungus::core::*;

assert_eq!((0..10).filter(|&x| x == 2).last().unwrap(), 2);

pub fn single(self) -> FuResult<Self::Item> where
    Self: Sized
[src]

If the iterator yields a single element, that element will be returned, otherwise an error will be returned.

Examples

use fungus::core::*;

assert_eq!((0..10).filter(|&x| x == 2).single().unwrap(), 2);

pub fn slice(self, left: isize, right: isize) -> Self where
    Self: Sized,
    Self: Clone,
    Self: DoubleEndedIterator
[src]

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 fungus::core::*;

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);

pub fn some(self) -> bool where
    Self: Sized
[src]

If the iterator yields at least one element, true will be returned else false

Examples

use fungus::core::*;

assert_eq!((0..10).filter(|&x| x == 2).some(), true);
Loading content...

Implementors

impl<T: ?Sized> IteratorExt for T where
    T: Iterator
[src]

Loading content...