-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge MergeBy
and MergeJoinBy
#701
Comments
I experimented a bit and what you want is for
It's conflicting. But then if we add a type
then we can have
Does it seems good to you? (changes in "src/merge_join.rs" and very little in "src/lib.rs").
|
Hi there. I'm not sure if I follow 100% wrt "conflicting". I think As such, I'd imagine this:
I am not sure if this design hits an unsovable obstacle somewhere, but for me it looks a bit clearer than basically copy-pasting/macro-generating two impls for |
I agree about not conflicting for the reason you mention, I was just being careful.
To match against the result of the user function, I needed |
Wow, that was fast. - Nice that it seems to work. As for the additional methods: Of course, I didn't see the whole implementation, but it sounds reasonable. |
Here is a commit for it. Seems reasonable to me too. |
First, I moved To merge implementations of "MergeBy" and "MergeJoinBy", I mostly struggled with the type "Merge" (how to discard "MergePredicate" and "MergeLte" for
If this is satisfying, should I merge files "merge_join.rs" into the newly created "adaptors/merge.rs" ? EDIT: In "OrderingOrBool" trait, I added |
Thank you for staying in touch. I see there are some valid questions, so I suggest to first focus on supporting Please see my comments there for specifics, but probably most important: Is the fourth type parameter in In addition, this commit introduced several trait bounds that look unneeded to me. We should add only the trait bounds required to support The idea of your transformation (i.e. having As said, let's keep it at supporting
I think we should fuse the input iterators (i.e. adapt
Good catch. Maybe that precludes merging the structs... We'll have to look into that.
I think most of the time we rely on the compiler, but afaik there are no definitive guidelines about |
You might have missed (or not) an edit of my comment, a fix about size_hint, seems simple enough to me. |
I did not find a way to have only three types. I was going with a trait MergePredicate (idea from how
With
I suppose it worries that there is a type out there implementing both
The constraint on Hence I add So I think |
Here is a new commit (in a new branch) with |
Following the last commit, add a PhantomData field on MergeJoinBy would allow me to remove |
Thanks for the update. I like how you were able to avoid the I still think it should be possible without Looking at this prototype, it seems that |
So I got rid of MergePredicate there. The diff between before the issue and now, it feels right. I could avoid code duplication (code below is in four Iterator methods), or not (it's not that bad).
I could work on bringing |
I'd say we should focus on supporting
|
Use All four points are done here (and small stupid duplicates removed). Although, I'm not sure the documentation sentence about "less" is clear enough. I changed the common example to show that the |
I should not have unwrapped Either in the first quickcheck (commit). |
I tried with
|
Hi, thanks so far. I realized we should keep the inners of |
|
Oh, cool. Maybe open a PR so we can have a last review? |
704: `MergeJoinBy` also accept functions returning `bool` r=jswrenn a=Philippe-Cholet Related to #701 . The produced iterator then yields `Either` items instead of `EitherOrBoth` items when the user function returns `Ordering`. Co-authored-by: Philippe-Cholet <[email protected]>
Now that the PR is merged, we can merge implementations as you first wanted. The way I see it,
Then
And MergeBy uses MergeJoinBy in its internal
The rest is really straightforward. I know it will pass tests as I experimented before. |
Hi @Philippe-Cholet , I think this design has two drawbacks:
Without having looked at the code too closely, I think we should express the affected iterators all as instances of
This could be realized by extending |
I kinda expected it about
|
After moving Merge/MergeBy into merge_join module to manipulate them all easily, I'm just really stuck. To be able to keep Both |
About |
I think I'm finally on the right path! To get rid of In Commit there but you might prefer to see the current code. |
Hi there, thanks for going through this. I do not have too much time right now, so just quick feedback: I think this is indeed taking the right turns! I skimmed the code, and I saw that you have four merge predicates:
Looks simple and good. Maybe we can simplify some I think that |
Thanks for the quick feedback. I only commented out Good catch, Note 1: But
Some impossible Note 2: EDIT: I could write a new |
From its trait documentation, we should implement Here, I think I made a mistake (being too fast).
instead of
|
Sounds right. |
FusedIterator' small fix.
I could
I think that would be clearer to people. What's your thought on that? Then should I open a pull request for review, or do you see changes to do? |
@phimuemue Little reminder. |
Hi, thanks for keeping in touch. What I see:
If all this passes our tests, can you open a PR? |
Thank you too for this long discussion, I initially thought it would be quickier. I don't like I don't see any way to avoid it, but maybe you do. Currently, Philippe-Cholet/itertools@c622606 . I'll make a PR once you find a way or are ok with the 4th type. |
I think I'm fine with |
It seems that
merge_join_by
/MergeJoinBy
is actually a more generic variant ofmerge
/MergeBy
.However, currently, the
MergeJoinBy
andMergeBy
are implemented independently (PutBack
vsPeekable
, fused behavior, requiringOrdering
vsbool
). The past showed that uniform implementations may be better.This change should not introduce breaking changes for users:
merge
,merge_by
andmerge_join_by
should stay usable as they are.However, I'd imagine that the general
merge_join_by
could also accept a comparator returningbool
(instead ofOrdering
) - this would free the users from having to deal with theEitherOrBoth::Both
case. I.e. I suggest that users should be able to write:When we tackle this, we should - as a first step - probably move all the
merge
-related functions into an own module.The text was updated successfully, but these errors were encountered: