MapExt

Trait MapExt 

Source
pub trait MapExt<I, O, E, R> {
    // Provided methods
    fn map<F>(self, f: F) -> Map<Self, F, O>
       where Self: Sized,
             O: HList,
             F: FunMut<O> { ... }
    fn map1<F>(self, f: F) -> Map1<Self, F, O>
       where Self: Sized,
             O: HList,
             F: FunMut<O> { ... }
    fn mapf<O2, F>(self, f: F) -> MapF<Self, F, O>
       where Self: Sized,
             F: FnMut(O) -> O2 { ... }
    fn map_err<E2, F>(self, f: F) -> MapErr<Self, F, E>
       where Self: Sized,
             F: FnMut(FatalError<E>) -> FatalError<E2> { ... }
}
Expand description

Combinator that transforms a part of a pipe

Provided Methods§

Source

fn map<F>(self, f: F) -> Map<Self, F, O>
where Self: Sized, O: HList, F: FunMut<O>,

Maps the output of a pipe O to O2 by applying a function to it.

Example:

assert_eq!(
    tag::<Error, _, _>("a").map(|_| (1, 2, 3)).apply("a"),
    Ok(("", (1, 2, 3)))
);
Source

fn map1<F>(self, f: F) -> Map1<Self, F, O>
where Self: Sized, O: HList, F: FunMut<O>,

Maps the output of a pipe O to O2 by applying a function to it. The result is mapped into a tuple

assert_eq!(
    tag::<Error, _, _>("a").map1(|_| (1, 2, 3)).apply("a"),
    Ok(("", ((1, 2, 3),)))
);
assert_eq!(tag::<Error, _, _>("a").map1(|_| 1).apply("a"), Ok(("", (1,))));
Source

fn mapf<O2, F>(self, f: F) -> MapF<Self, F, O>
where Self: Sized, F: FnMut(O) -> O2,

Maps the output of a pipe O to O2 by applying a function to it. The result is mapped into a tuple

assert_eq!(tag::<Error, _, _>("a").mapf(|_| 1).apply("a"), Ok(("", 1)));
assert_eq!(tag::<Error, _, _>("a").mapf(|(x,)| x).apply("a"), Ok(("", "a")));
Source

fn map_err<E2, F>(self, f: F) -> MapErr<Self, F, E>
where Self: Sized, F: FnMut(FatalError<E>) -> FatalError<E2>,

Maps an error FatalError<E> to FatalError<E2> by applying a function to the error.

#[derive(Debug, PartialEq)]
struct MyError;

assert_eq!(tag::<Error, _, _>("a").map_err(|_| FatalError::Error(MyError)).apply("b"),
           Err(FatalError::Error(MyError))
);

Implementors§

Source§

impl<I, O, E, R, P> MapExt<I, O, E, R> for P
where P: Pipe<I, O, E, R>,