Refactor Option::filter method

This commit is contained in:
Shanavas M 2017-11-11 17:01:55 +03:00
parent 69ee5a8a97
commit abff092f90

View File

@ -634,17 +634,13 @@ impl<T> Option<T> {
#[inline] #[inline]
#[unstable(feature = "option_filter", issue = "45860")] #[unstable(feature = "option_filter", issue = "45860")]
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self { pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
match self { if let Some(x) = self {
Some(x) => {
if predicate(&x) { if predicate(&x) {
Some(x) return Some(x)
} else { }
}
None None
} }
}
None => None,
}
}
/// Returns the option if it contains a value, otherwise returns `optb`. /// Returns the option if it contains a value, otherwise returns `optb`.
/// ///