Trait Iterflow

Source
pub trait Iterflow: Iterator {
    // Provided methods
    fn map_err<F, T, E, R>(self, op: F) -> MapErr<Self, F>
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(E) -> R { ... }
    fn map_ok<F, T, U, E>(self, op: F) -> MapOk<Self, F>
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(T) -> U { ... }
    fn map_ok_borrow<F, T, U, E>(self, op: F) -> MapOkBorrow<Self, F>
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(&T) -> U { ... }
    fn and_then<F, T, U, E, R>(self, op: F) -> AndThen<Self, F>
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(T) -> Result<U, R>,
             E: From<R> { ... }
    fn and_then_borrow<F, T, U, E, R>(self, op: F) -> AndThenBorrow<Self, F>
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(&T) -> Result<U, R>,
             E: From<R> { ... }
    fn flat_map_ok<F, T, U, E>(self, op: F) -> FlattenOk<MapOk<Self, F>, U, E> 
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(T) -> U,
             U: IntoIterator { ... }
    fn flat_map_ok_borrow<F, T, U, E>(
        self,
        op: F,
    ) -> FlattenOk<MapOkBorrow<Self, F>, U, E> 
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(&T) -> U,
             U: IntoIterator { ... }
    fn and_then_flat<F, T, U, E, R>(
        self,
        op: F,
    ) -> FlattenOk<AndThen<Self, F>, U, E> 
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(T) -> Result<U, R>,
             E: From<R>,
             U: IntoIterator { ... }
    fn and_then_flat_borrow<F, T, U, E, R>(
        self,
        op: F,
    ) -> FlattenOk<AndThenBorrow<Self, F>, U, E> 
       where Self: Iterator<Item = Result<T, E>> + Sized,
             F: FnMut(&T) -> Result<U, R>,
             E: From<R>,
             U: IntoIterator { ... }
    fn finish<T, U, E>(self) -> Result<U, E>
       where Self: Iterator<Item = Result<T, E>> + Sized,
             Result<U, E>: FromIterator<Result<T, E>> { ... }
    fn finish_vec<T, E>(self) -> Result<Vec<T>, E>
       where Self: Iterator<Item = Result<T, E>> + Sized { ... }
}
Expand description

An Iterator blanket implementation that provides extra adaptors and methods.

Provided Methods§

Source

fn map_err<F, T, E, R>(self, op: F) -> MapErr<Self, F>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(E) -> R,

Return an iterator adaptor that applies the provided closure to every Result::Err value. Result::Ok values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(41), Err(false), Err(true)];
let it = input.into_iter().map_err(|b| !b);
iter_flow::assert_equal(it, vec![Ok(41), Err(true), Err(false)]);
Source

fn map_ok<F, T, U, E>(self, op: F) -> MapOk<Self, F>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(T) -> U,

Return an iterator adaptor that applies the provided closure to every Result::Ok value. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(41), Err(false), Ok(11)];
let it = input.into_iter().map_ok(|i| i + 1);
iter_flow::assert_equal(it, vec![Ok(42), Err(false), Ok(12)]);
Source

fn map_ok_borrow<F, T, U, E>(self, op: F) -> MapOkBorrow<Self, F>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(&T) -> U,

Return an iterator adaptor that applies the provided closure to every Result::Ok value. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(41), Err(false), Ok(11)];
let it = input.into_iter().map_ok_borrow(|i: &i32| i + 1);
iter_flow::assert_equal(it, vec![Ok(42), Err(false), Ok(12)]);
Source

fn and_then<F, T, U, E, R>(self, op: F) -> AndThen<Self, F>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(T) -> Result<U, R>, E: From<R>,

Return an iterator adaptor that applies the provided fallible closure to every Result::Ok value. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(0), Err(false), Ok(11)];
let it = input
    .into_iter()
    .and_then(|i| if i == 0 { Err(false) } else { Ok(i - 1) });
iter_flow::assert_equal(it, vec![Err(false), Err(false), Ok(10)]);
Source

fn and_then_borrow<F, T, U, E, R>(self, op: F) -> AndThenBorrow<Self, F>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(&T) -> Result<U, R>, E: From<R>,

Return an iterator adaptor that applies the provided fallible closure to every Result::Ok value. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(0), Err(false), Ok(11)];
let it = input
    .into_iter()
    .and_then_borrow(|i: &i32| if i == &0 { Err(false) } else { Ok(i - 1) });
iter_flow::assert_equal(it, vec![Err(false), Err(false), Ok(10)]);
Source

fn flat_map_ok<F, T, U, E>(self, op: F) -> FlattenOk<MapOk<Self, F>, U, E>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(T) -> U, U: IntoIterator,

Return an iterator adaptor that applies the provided closure to every Result::Ok value and then flattens it. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(41), Err(false), Ok(11)];
let it = input.into_iter().flat_map_ok(|i| (i..=(i + 1)));
iter_flow::assert_equal(it, vec![Ok(41), Ok(42), Err(false), Ok(11), Ok(12)]);
Source

fn flat_map_ok_borrow<F, T, U, E>( self, op: F, ) -> FlattenOk<MapOkBorrow<Self, F>, U, E>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(&T) -> U, U: IntoIterator,

Return an iterator adaptor that applies the provided closure to every Result::Ok value and then flattens it. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(41), Err(false), Ok(11)];
let it = input
    .into_iter()
    .flat_map_ok_borrow(|i: &i32| (*i..=(*i + 1)));
iter_flow::assert_equal(it, vec![Ok(41), Ok(42), Err(false), Ok(11), Ok(12)]);
Source

fn and_then_flat<F, T, U, E, R>( self, op: F, ) -> FlattenOk<AndThen<Self, F>, U, E>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(T) -> Result<U, R>, E: From<R>, U: IntoIterator,

Return an iterator adaptor that applies the provided fallible closure to every Result::Ok value and then flattens it. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(0), Err(false), Ok(11)];
let it = input.into_iter().and_then_flat(|i| {
    if i == 0 {
        Err(false)
    } else {
        Ok(((i - 1)..=i))
    }
});
iter_flow::assert_equal(it, vec![Err(false), Err(false), Ok(10), Ok(11)]);
Source

fn and_then_flat_borrow<F, T, U, E, R>( self, op: F, ) -> FlattenOk<AndThenBorrow<Self, F>, U, E>
where Self: Iterator<Item = Result<T, E>> + Sized, F: FnMut(&T) -> Result<U, R>, E: From<R>, U: IntoIterator,

Return an iterator adaptor that applies the provided fallible closure to every Result::Ok value and then flattens it. Result::Err values are unchanged.

use iter_flow::Iterflow;

let input = vec![Ok(0), Err(false), Ok(11)];
let it = input.into_iter().and_then_flat_borrow(|i: &i32| {
    if i == &0 {
        Err(false)
    } else {
        Ok(((*i - 1)..=*i))
    }
});
iter_flow::assert_equal(it, vec![Err(false), Err(false), Ok(10), Ok(11)]);
Source

fn finish<T, U, E>(self) -> Result<U, E>
where Self: Iterator<Item = Result<T, E>> + Sized, Result<U, E>: FromIterator<Result<T, E>>,

.finish() is simply a type specialization of Iterator::collect, for convenience.

Source

fn finish_vec<T, E>(self) -> Result<Vec<T>, E>
where Self: Iterator<Item = Result<T, E>> + Sized,

.finish_vec() is simply a type specialization of Iterator::collect, for convenience.

Implementors§

Source§

impl<T> Iterflow for T
where T: Iterator + ?Sized,