We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Interleave::fold
1 parent 5a321ca commit 824b2dfCopy full SHA for 824b2df
src/adaptors/mod.rs
@@ -76,6 +76,28 @@ where
76
fn size_hint(&self) -> (usize, Option<usize>) {
77
size_hint::add(self.a.size_hint(), self.b.size_hint())
78
}
79
+
80
+ fn fold<B, F>(self, mut init: B, mut f: F) -> B
81
+ where
82
+ F: FnMut(B, Self::Item) -> B,
83
+ {
84
+ let Self { a, mut b, flag } = self;
85
+ if flag {
86
+ if let Some(y) = b.next() {
87
+ init = f(init, y);
88
+ } else {
89
+ return a.fold(init, f);
90
+ }
91
92
+ init = a.fold(init, |mut acc, x| {
93
+ acc = f(acc, x);
94
95
+ acc = f(acc, y);
96
97
+ acc
98
+ });
99
+ b.fold(init, f)
100
101
102
103
impl<I, J> FusedIterator for Interleave<I, J>
0 commit comments