File tree Expand file tree Collapse file tree 1 file changed +15
-14
lines changed Expand file tree Collapse file tree 1 file changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -40,20 +40,21 @@ where
40
40
41
41
fn next ( & mut self ) -> Option < Self :: Item > {
42
42
// this fuses the iterator
43
- let mut last = match self . last . take ( ) {
44
- None => return None ,
45
- Some ( x) => x,
46
- } ;
47
- for next in & mut self . iter {
48
- match self . f . coalesce_pair ( last, next) {
49
- Ok ( joined) => last = joined,
50
- Err ( ( last_, next_) ) => {
51
- self . last = Some ( next_) ;
52
- return Some ( last_) ;
53
- }
54
- }
55
- }
56
- Some ( last)
43
+ let last = self . last . take ( ) ?;
44
+
45
+ let self_last = & mut self . last ;
46
+ let self_f = & mut self . f ;
47
+ Some (
48
+ self . iter
49
+ . try_fold ( last, |last, next| match self_f. coalesce_pair ( last, next) {
50
+ Ok ( joined) => Ok ( joined) ,
51
+ Err ( ( last_, next_) ) => {
52
+ * self_last = Some ( next_) ;
53
+ Err ( last_)
54
+ }
55
+ } )
56
+ . unwrap_or_else ( |x| x) ,
57
+ )
57
58
}
58
59
59
60
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
You can’t perform that action at this time.
0 commit comments