Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 24, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/f899a30f0a009a32191da16527bbf5e8 to your computer and use it in GitHub Desktop.
Save rust-play/f899a30f0a009a32191da16527bbf5e8 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
let val = Some(10);
//let val = None;
let z = maybe_add_four(val);
println!("{:?}", z)
}
fn maybe_add_four(y: Option<i32>) -> Option<i32> {
let ret = y.map(|x| x + 4);
assert_eq!(y, Some(10));
ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment