Skip to content

Commit

Permalink
PadUsing::fold
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet authored and jswrenn committed Dec 24, 2023
1 parent a90f095 commit e3f8b27
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pad_tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ where
let tail = self.min.saturating_sub(self.pos);
size_hint::max(self.iter.size_hint(), (tail, Some(tail)))
}

fn fold<B, G>(self, mut init: B, mut f: G) -> B
where
G: FnMut(B, Self::Item) -> B,
{
let mut pos = self.pos;
init = self.iter.fold(init, |acc, item| {
pos += 1;
f(acc, item)
});
(pos..self.min).map(self.filler).fold(init, f)
}
}

impl<I, F> DoubleEndedIterator for PadUsing<I, F>
Expand Down

0 comments on commit e3f8b27

Please sign in to comment.