Skip to content

Commit fb513aa

Browse files
committed
Update foreach to use .fold()
For interesting reasons..
1 parent a05e4d7 commit fb513aa

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,8 @@ pub trait Itertools : Iterator {
985985
fn foreach<F>(&mut self, mut f: F)
986986
where F: FnMut(Self::Item)
987987
{
988-
for elt in self {
989-
f(elt)
990-
}
988+
// use fold to exploit iterator-specific implementations
989+
self.fold((), move |(), element| f(element))
991990
}
992991

993992
/// `.collect_vec()` is simply a type specialization of `.collect()`,

0 commit comments

Comments
 (0)