Refactor Option::filter method
This commit is contained in:
parent
69ee5a8a97
commit
abff092f90
@ -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`.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user