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 eeda182 commit 7f5f00dCopy full SHA for 7f5f00d
src/adaptors/mod.rs
@@ -76,6 +76,30 @@ 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 { mut a, mut b, flag } = self;
85
+ if flag {
86
+ match b.next() {
87
+ Some(y) => init = f(init, y),
88
+ None => return a.fold(init, f),
89
+ }
90
91
+ let res = a.try_fold(init, |mut acc, x| {
92
+ acc = f(acc, x);
93
94
+ Some(y) => Ok(f(acc, y)),
95
+ None => Err(acc),
96
97
+ });
98
+ match res {
99
+ Ok(acc) => b.fold(acc, f),
100
+ Err(acc) => a.fold(acc, f),
101
102
103
104
105
impl<I, J> FusedIterator for Interleave<I, J>
0 commit comments