Handling Option with map
📝 RustSafely transform the inner value of an Option by using map to apply a function only when it's Some, and keep it None otherwise.
Rust
fn main() { let somevalue = Some(10); let doubled = somevalue.map(|v| v 2); println!("{:?}", doubled);
}
Comments
No comments yet. Start the discussion.