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