Skip to content

Commit 347d52a

Browse files
committed
Implement ZipEq::fold
1 parent 37c54d1 commit 347d52a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/zip_eq_impl.rs

+14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ where
5252
}
5353
}
5454

55+
#[inline]
56+
fn fold<B, F>(self, init: B, mut f: F) -> B
57+
where
58+
Self: Sized,
59+
F: FnMut(B, Self::Item) -> B,
60+
{
61+
let Self { a, mut b } = self;
62+
63+
a.fold(init, |acc, x| match b.next() {
64+
Some(y) => f(acc, (x, y)),
65+
None => panic!("itertools: .zip_eq() reached end of one iterator before the other"),
66+
})
67+
}
68+
5569
fn size_hint(&self) -> (usize, Option<usize>) {
5670
size_hint::min(self.a.size_hint(), self.b.size_hint())
5771
}

0 commit comments

Comments
 (0)