Skip to content

Commit 913469e

Browse files
committed
Inline CoalesceCore into Coalesce (2)
1 parent 8a05e9e commit 913469e

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/adaptors/mod.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -605,31 +605,6 @@ impl<I, J, F> Iterator for MergeBy<I, J, F>
605605
}
606606
}
607607

608-
impl<I, F, T> Coalesce<I, F, T>
609-
where I: Iterator,
610-
F: CoalescePredicate<I::Item, T>,
611-
{
612-
fn next_with(&mut self) -> Option<T> {
613-
// this fuses the iterator
614-
let mut last = match self.last.take() {
615-
None => return None,
616-
Some(x) => x,
617-
};
618-
for next in &mut self.iter {
619-
match self.f.coalesce_pair(last, next) {
620-
Ok(joined) => last = joined,
621-
Err((last_, next_)) => {
622-
self.last = Some(next_);
623-
return Some(last_);
624-
}
625-
}
626-
}
627-
628-
Some(last)
629-
}
630-
631-
}
632-
633608
/// An iterator adaptor that may join together adjacent elements.
634609
///
635610
/// See [`.coalesce()`](../trait.Itertools.html#method.coalesce) for more information.
@@ -685,7 +660,21 @@ impl<I, F, T> Iterator for Coalesce<I, F, T>
685660
type Item = T;
686661

687662
fn next(&mut self) -> Option<Self::Item> {
688-
self.next_with()
663+
// this fuses the iterator
664+
let mut last = match self.last.take() {
665+
None => return None,
666+
Some(x) => x,
667+
};
668+
for next in &mut self.iter {
669+
match self.f.coalesce_pair(last, next) {
670+
Ok(joined) => last = joined,
671+
Err((last_, next_)) => {
672+
self.last = Some(next_);
673+
return Some(last_);
674+
}
675+
}
676+
}
677+
Some(last)
689678
}
690679

691680
fn size_hint(&self) -> (usize, Option<usize>) {

0 commit comments

Comments
 (0)