Skip to content

Commit

Permalink
Refactor IntersperseWith::next
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet authored and jswrenn committed Nov 13, 2023
1 parent b76172b commit 4f22173
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/intersperse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,20 @@ where
type Item = I::Item;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.peek.is_some() {
self.peek.take()
} else {
self.peek = self.iter.next();
if self.peek.is_some() {
Some(self.element.generate())
} else {
None
}
let Self {
element,
iter,
peek,
} = self;
match peek {
item @ Some(_) => item.take(),
None => match iter.next() {
new @ Some(_) => {
*peek = new;
Some(element.generate())
}
None => None,
},
}
}

Expand Down

0 comments on commit 4f22173

Please sign in to comment.