File tree 1 file changed +14
-7
lines changed
1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -2099,19 +2099,26 @@ pub trait Itertools : Iterator {
2099
2099
/// The big difference between the computations of `result2` and `result3` is that while
2100
2100
/// `fold()` called the provided closure for every item of the callee iterator,
2101
2101
/// `fold_while()` actually stopped iterating as soon as it encountered `Fold::Done(_)`.
2102
- #[ deprecated( note="Use .try_fold() instead" , since="0.8.0" ) ]
2103
2102
fn fold_while < B , F > ( & mut self , init : B , mut f : F ) -> FoldWhile < B >
2104
2103
where Self : Sized ,
2105
2104
F : FnMut ( B , Self :: Item ) -> FoldWhile < B >
2106
2105
{
2107
- let mut acc = init;
2108
- for item in self {
2109
- match f ( acc, item) {
2110
- FoldWhile :: Continue ( res) => acc = res,
2111
- res @ FoldWhile :: Done ( _) => return res,
2106
+ use Result :: {
2107
+ Ok as Continue ,
2108
+ Err as Break ,
2109
+ } ;
2110
+
2111
+ let result = self . try_fold ( init, #[ inline( always) ] |acc, v|
2112
+ match f ( acc, v) {
2113
+ FoldWhile :: Continue ( acc) => Continue ( acc) ,
2114
+ FoldWhile :: Done ( acc) => Break ( acc) ,
2112
2115
}
2116
+ ) ;
2117
+
2118
+ match result {
2119
+ Continue ( acc) => FoldWhile :: Continue ( acc) ,
2120
+ Break ( acc) => FoldWhile :: Done ( acc) ,
2113
2121
}
2114
- FoldWhile :: Continue ( acc)
2115
2122
}
2116
2123
2117
2124
/// Iterate over the entire iterator and add all the elements.
You can’t perform that action at this time.
0 commit comments