Skip to content

Commit

Permalink
Unalias MergeBy
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Aug 31, 2023
1 parent 8f3c11b commit 6061c96
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/merge_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ pub fn merge<I, J>(i: I, j: J) -> Merge<<I as IntoIterator>::IntoIter, <J as Int
/// Iterator element type is `I::Item`.
///
/// See [`.merge_by()`](crate::Itertools::merge_by) for more information.
pub type MergeBy<I, J, F> = InternalMergeJoinBy<I, J, F>;
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct MergeBy<I: Iterator, J: Iterator, F> {
left: PutBack<Fuse<I>>,
right: PutBack<Fuse<J>>,
cmp_fn: F,
}

/// Create a `MergeBy` iterator.
pub fn merge_by_new<I, J, F>(a: I, b: J, cmp: F) -> MergeBy<I::IntoIter, J::IntoIter, F>
where I: IntoIterator,
J: IntoIterator<Item = I::Item>,
{
InternalMergeJoinBy {
MergeBy {
left: put_back(a.into_iter().fuse()),
right: put_back(b.into_iter().fuse()),
cmp_fn: cmp,
Expand All @@ -70,7 +75,7 @@ pub fn merge_join_by<I, J, F, T>(left: I, right: J, cmp_fn: F)
J: IntoIterator,
F: FnMut(&I::Item, &J::Item) -> T,
{
InternalMergeJoinBy {
MergeBy {
left: put_back(left.into_iter().fuse()),
right: put_back(right.into_iter().fuse()),
cmp_fn: MergeFuncLR(cmp_fn, PhantomData),
Expand All @@ -80,14 +85,7 @@ pub fn merge_join_by<I, J, F, T>(left: I, right: J, cmp_fn: F)
/// An iterator adaptor that merge-joins items from the two base iterators in ascending order.
///
/// See [`.merge_join_by()`](crate::Itertools::merge_join_by) for more information.
pub type MergeJoinBy<I, J, F> = InternalMergeJoinBy<I, J, MergeFuncLR<F, <F as FuncLR<<I as Iterator>::Item, <J as Iterator>::Item>>::T>>;

#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct InternalMergeJoinBy<I: Iterator, J: Iterator, F> {
left: PutBack<Fuse<I>>,
right: PutBack<Fuse<J>>,
cmp_fn: F,
}
pub type MergeJoinBy<I, J, F> = MergeBy<I, J, MergeFuncLR<F, <F as FuncLR<<I as Iterator>::Item, <J as Iterator>::Item>>::T>>;

#[derive(Clone, Debug)]
pub struct MergeFuncLR<F, T>(F, PhantomData<T>);
Expand Down Expand Up @@ -206,7 +204,7 @@ impl<T: PartialOrd> OrderingOrBool<T, T> for MergeLte {
}
}

impl<I, J, F> Clone for InternalMergeJoinBy<I, J, F>
impl<I, J, F> Clone for MergeBy<I, J, F>
where I: Iterator,
J: Iterator,
PutBack<Fuse<I>>: Clone,
Expand All @@ -216,16 +214,16 @@ impl<I, J, F> Clone for InternalMergeJoinBy<I, J, F>
clone_fields!(left, right, cmp_fn);
}

impl<I, J, F> fmt::Debug for InternalMergeJoinBy<I, J, F>
impl<I, J, F> fmt::Debug for MergeBy<I, J, F>
where I: Iterator + fmt::Debug,
I::Item: fmt::Debug,
J: Iterator + fmt::Debug,
J::Item: fmt::Debug,
{
debug_fmt_fields!(InternalMergeJoinBy, left, right);
debug_fmt_fields!(MergeBy, left, right);
}

impl<I, J, F, T> Iterator for InternalMergeJoinBy<I, J, F>
impl<I, J, F, T> Iterator for MergeBy<I, J, F>
where I: Iterator,
J: Iterator,
F: OrderingOrBool<I::Item, J::Item, Out = T>,
Expand Down Expand Up @@ -328,7 +326,7 @@ impl<I, J, F, T> Iterator for InternalMergeJoinBy<I, J, F>
}
}

impl<I, J, F, T> FusedIterator for InternalMergeJoinBy<I, J, F>
impl<I, J, F, T> FusedIterator for MergeBy<I, J, F>
where
I: Iterator,
J: Iterator,
Expand Down

0 comments on commit 6061c96

Please sign in to comment.