Skip to content

Instantly share code, notes, and snippets.

@shakyShane
Created September 24, 2018 08:25
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 shakyShane/ed7d6e69e3283ce98f5563502109c8d4 to your computer and use it in GitHub Desktop.
Save shakyShane/ed7d6e69e3283ce98f5563502109c8d4 to your computer and use it in GitHub Desktop.
///
/// A simple way to apply both a predicate
/// and default value when dealing with an option.
///
fn is_legal(age: Option<usize>) -> bool {
age.map(|x| x >= 18).unwrap_or(false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment