Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Aug 12, 2022
1 parent 69fc19a commit 7611d22
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/src/iter/adapters/array_chunks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::array;
use crate::iter::{FusedIterator, Iterator};
use crate::iter::{ByRefSized, FusedIterator, Iterator};
use crate::ops::{ControlFlow, NeverShortCircuit, Try};

/// An iterator over `N` elements of the iterator at a time.
Expand Down Expand Up @@ -82,12 +82,12 @@ where
}
}

fn fold<B, F>(mut self, init: B, mut f: F) -> B
fn fold<B, F>(mut self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
self.try_fold(init, |acc, x| NeverShortCircuit(f(acc, x))).0
self.try_fold(init, NeverShortCircuit::wrap_mut_2(f)).0
}
}

Expand All @@ -111,25 +111,27 @@ where
self.next_back_remainder();

let mut acc = init;
let mut iter = self.iter.by_ref().rev();
let mut iter = ByRefSized(&mut self.iter).rev();

// NB remainder is handled by `next_back_remainder`, so
// `next_chunk` can't return `Err` with non-empty remainder
// (assuming correct `I as ExactSizeIterator` impl).
while let Ok(mut chunk) = iter.next_chunk() {
// FIXME: do not do double reverse
// (we could instead add `next_chunk_back` for example)
chunk.reverse();
acc = f(acc, chunk)?
}

try { acc }
}

fn rfold<B, F>(mut self, init: B, mut f: F) -> B
fn rfold<B, F>(mut self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
self.try_rfold(init, |acc, x| NeverShortCircuit(f(acc, x))).0
self.try_rfold(init, NeverShortCircuit::wrap_mut_2(f)).0
}
}

Expand Down

0 comments on commit 7611d22

Please sign in to comment.