Loading RustViz Engine...
Build custom MyOption enum implementing map, and_then, and unwrap_or.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub enum MyOption<T> {
Some(T),
None,
}
impl<T> MyOption<T> {
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> MyOption<U> {
match self {
MyOption::Some(x) => MyOption::Some(f(x)),
MyOption::None => MyOption::None,
}
}
pub fn and_then<U, F: FnOnce(T) -> MyOption<U>>(self, f: F) -> MyOption<U> {
match self {
MyOption::Some(x) => f(x),
MyOption::None => MyOption::None,
}
}
}