Skip to content

Commit 6ff207b

Browse files
committed
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
1 parent 62f1d68 commit 6ff207b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/libstd/option.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,13 @@ impl<T> Option<T> {
295295

296296
/// Applies a function zero or more times until the result is `None`.
297297
#[inline]
298-
pub fn while_some(self, blk: |v: T| -> Option<T>) {
298+
pub fn while_some(self, f: |v: T| -> Option<T>) {
299299
let mut opt = self;
300-
while opt.is_some() {
301-
opt = blk(opt.unwrap());
300+
loop {
301+
match opt {
302+
Some(x) => opt = f(x),
303+
None => break
304+
}
302305
}
303306
}
304307

0 commit comments

Comments
 (0)