diff --git a/src/take_while_inclusive.rs b/src/take_while_inclusive.rs index 5207d8a01..077b95498 100644 --- a/src/take_while_inclusive.rs +++ b/src/take_while_inclusive.rs @@ -64,6 +64,28 @@ where (0, self.iter.size_hint().1) } } + + fn fold(mut self, init: B, mut f: Fold) -> B + where + Fold: FnMut(B, Self::Item) -> B, + { + if self.done { + init + } else { + let predicate = &mut self.predicate; + self.iter + .try_fold(init, |mut acc, item| { + let is_ok = predicate(&item); + acc = f(acc, item); + if is_ok { + Ok(acc) + } else { + Err(acc) + } + }) + .unwrap_or_else(|err| err) + } + } } impl FusedIterator for TakeWhileInclusive