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.
RepeatN::fold
1 parent 451c72a commit 7c5a5c0Copy full SHA for 7c5a5c0
src/repeatn.rs
@@ -44,6 +44,20 @@ where
44
fn size_hint(&self) -> (usize, Option<usize>) {
45
(self.n, Some(self.n))
46
}
47
+
48
+ fn fold<B, F>(self, mut init: B, mut f: F) -> B
49
+ where
50
+ F: FnMut(B, Self::Item) -> B,
51
+ {
52
+ match self {
53
+ Self { elt: Some(elt), n } => {
54
+ debug_assert!(n > 0);
55
+ init = (1..n).map(|_| elt.clone()).fold(init, &mut f);
56
+ f(init, elt)
57
+ }
58
+ _ => init,
59
60
61
62
63
impl<A> DoubleEndedIterator for RepeatN<A>
0 commit comments