Skip to content

Commit 0205bd5

Browse files
committed
Introduce CoalesceBy (2) generalize it to coalesce to a different type
Required for Dedup(By)WithCount.
1 parent 7f2d460 commit 0205bd5

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/adaptors/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,12 @@ impl<I, T> CoalesceCore<I, T>
649649
///
650650
/// See [`.coalesce()`](../trait.Itertools.html#method.coalesce) for more information.
651651
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
652-
pub type Coalesce<I, F> = CoalesceBy<I, F>;
652+
pub type Coalesce<I, F> = CoalesceBy<I, F, <I as Iterator>::Item>;
653653

654-
pub struct CoalesceBy<I, F>
654+
pub struct CoalesceBy<I, F, T>
655655
where I: Iterator
656656
{
657-
iter: CoalesceCore<I, I::Item>,
657+
iter: CoalesceCore<I, T>,
658658
f: F,
659659
}
660660

@@ -670,16 +670,15 @@ impl<F, Item, T> CoalescePredicate<Item, T> for F
670670
}
671671
}
672672

673-
impl<I: Clone, F: Clone> Clone for CoalesceBy<I, F>
673+
impl<I: Clone, F: Clone, T: Clone> Clone for CoalesceBy<I, F, T>
674674
where I: Iterator,
675-
I::Item: Clone
676675
{
677676
clone_fields!(iter, f);
678677
}
679678

680-
impl<I, F> fmt::Debug for CoalesceBy<I, F>
679+
impl<I, F, T> fmt::Debug for CoalesceBy<I, F, T>
681680
where I: Iterator + fmt::Debug,
682-
I::Item: fmt::Debug,
681+
T: fmt::Debug,
683682
{
684683
debug_fmt_fields!(CoalesceBy, iter);
685684
}
@@ -697,11 +696,11 @@ pub fn coalesce<I, F>(mut iter: I, f: F) -> Coalesce<I, F>
697696
}
698697
}
699698

700-
impl<I, F> Iterator for CoalesceBy<I, F>
699+
impl<I, F, T> Iterator for CoalesceBy<I, F, T>
701700
where I: Iterator,
702-
F: CoalescePredicate<I::Item, I::Item>
701+
F: CoalescePredicate<I::Item, T>
703702
{
704-
type Item = I::Item;
703+
type Item = T;
705704

706705
fn next(&mut self) -> Option<Self::Item> {
707706
let f = &mut self.f;

0 commit comments

Comments
 (0)