-
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
Add comm iterator (inspired by Unix comm command)? #963
Comments
Similarly to what we did with Have you tried to use |
Is this to reduce code duplication due to monomorphization? That is the only reason to prefer one over the other that I can think of.
Oh cool, we live and learn.
It was too convoluted for me to find that. I kept looking for names like "diff", "common", "comm", etc. But looking at the example for merge_join_by it seems to fit. That Both returns, well, both values instead of de-duplicating is not something I need, but it should be fine (I'll just throw one away) |
To get the If it fits but is a bit convulated, then maybe we can have create a method wrapping this |
Thank you, it is always good to learn about idiomatic API design.
Using it is not convoluted, it works very well. What was convoluted was finding it. Perhaps adding some rustdoc aliases might help people locate it. I would suggest
|
I did not encounter any real use of doc aliases before, that's interesting. I see the interest of having @jswrenn @phimuemue Any objection to use doc aliases? PS: I note that doc aliases requires Rust 1.48 and we just increased the MSRV from 1.43.1 to 1.63 so it can be used! |
It seems the current first example matches my situation (though it is using an explicit closure rather than just using Maybe it could be made more obvious with a comment (since it uses a range for one of the inputs, so it is not as obvious what it is doing). Something like: itertools::assert_equal(
// This performs a diff in the style of the Unix command comm(1), generalised
// to arbitrary types rather than text.
a.merge_join_by(b, |i, j| i.cmp(j)),
vec![Both(0, 0), Left(2), Right(3), Left(4), Both(6, 6), Left(1), Right(9)]
); The advantage of this is that if you just do Ctrl+F and type comm or diff on the page (as opposed to using the rustdoc search feature) you will find it. (Rust crates often have excellent documentation, except for discoverability when you don't know the term you are looking for. That is not an easy problem, and the fact that rustdoc search doesn't do full text search doesn't help. At least itertools is based on a central trait, so almost everything can be found on a single HTML page. As such Ctrl-F works okay for it. Good luck finding things in crates like regex or clap if you don't know the correct name!) |
I agree that rustdoc-search is sometimes not as helpful as it could be (especially for a complex crate like clap) but we are quite centralized with the So doc aliases and a comment, fine by me. |
@VorpalBlade Done in #966, you don't need to do it yourself. |
Oops, thought you said done, didn't realise it wasn't merged yet. |
I recently had the need for comparing sorted iterators to figure out which elements were only in the left, right or both iterators. This is basically the same operation as comm(1) but generalised to iterators.
So I wrote an implementation that works for my purposes. However, this is a side thing in the crate I'm working on, it doesn't fit as an exposed API from it. So I wonder if there is any interest in cleaning up this and going through the effort of making a PR for itertools (where it seems like a good fit).
Below is the basic implementation (excluding tests,
Clone
,Debug
,FusedIterator
and other things that aren't core to the API). I left the doctest in to show how it is used. There are probably ways to improve all of this, but lets see if there is any interest in this at all before I spend time on that.The text was updated successfully, but these errors were encountered: