Refactored while_some (libstd/option.rs)
The old 'while' needed to match 2 times for each iteration. With the new 'loop' there is just one match needed. I have also replaced 'blk' by 'f' to be more consistent with parameter names in other functions that are implemented for Option
This commit is contained in:
parent
62f1d68439
commit
6ff207b415
@ -295,10 +295,13 @@ pub fn filtered(self, f: |t: &T| -> bool) -> Option<T> {
|
||||
|
||||
/// Applies a function zero or more times until the result is `None`.
|
||||
#[inline]
|
||||
pub fn while_some(self, blk: |v: T| -> Option<T>) {
|
||||
pub fn while_some(self, f: |v: T| -> Option<T>) {
|
||||
let mut opt = self;
|
||||
while opt.is_some() {
|
||||
opt = blk(opt.unwrap());
|
||||
loop {
|
||||
match opt {
|
||||
Some(x) => opt = f(x),
|
||||
None => break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user