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§
Sourcefn map<F>(self, f: F) -> Map<Self, F, O>
fn map<F>(self, f: F) -> Map<Self, F, 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)))
);Sourcefn map1<F>(self, f: F) -> Map1<Self, F, O>
fn map1<F>(self, f: F) -> Map1<Self, F, 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,))));Sourcefn mapf<O2, F>(self, f: F) -> MapF<Self, F, O>
fn mapf<O2, F>(self, f: F) -> MapF<Self, F, 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").mapf(|_| 1).apply("a"), Ok(("", 1)));
assert_eq!(tag::<Error, _, _>("a").mapf(|(x,)| x).apply("a"), Ok(("", "a")));Sourcefn map_err<E2, F>(self, f: F) -> MapErr<Self, F, E>
fn map_err<E2, F>(self, f: F) -> MapErr<Self, F, E>
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))
);