stdlib: Add map* for Option and Result
This commit is contained in:
parent
c5e817f1e5
commit
dc1c9bdd6d
@ -19,4 +19,11 @@ impl Option {
|
|||||||
None => true,
|
None => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Maps from one option space to another
|
||||||
|
// pub fn map<U>(self: Self, f: fn(T) -> U) -> Option<U> {
|
||||||
|
// match self {
|
||||||
|
// Some(value) => Some(f(value)),
|
||||||
|
// None => None,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,18 @@ impl Result {
|
|||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Maps the value inside the Result::Ok, leaving errors alone.
|
||||||
|
// pub fn map<U>(self, f: fn(T) -> U) -> Result<U, E> {
|
||||||
|
// match self {
|
||||||
|
// Ok(t) => Ok(f(t)),
|
||||||
|
// Err(e) => Err(e),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
/// Maps the value inside the Result::Err, leaving values alone.
|
||||||
|
// pub fn map_err<F>(self, f: fn(E) -> F) -> Result<T, F> {
|
||||||
|
// match self {
|
||||||
|
// Ok(t) => Ok(t),
|
||||||
|
// Err(e) => Err(f(e)),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user