Skip to content
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

FEAT: implement .all_unique() #241

Merged
merged 1 commit into from Jan 18, 2021
Merged

FEAT: implement .all_unique() #241

merged 1 commit into from Jan 18, 2021

Conversation

samueltardieu
Copy link
Contributor

In day 4 of the Advent of Code 2017 (https://adventofcode.com/),
all_unique() would have been useful. It is already present
in some languages such as Factor's all-unique?.

@bluss
Copy link
Member

bluss commented Jan 6, 2018

Hi, I have to say I have had problem seeing the value in such a method, but I have also had trouble coming up with examples for how to do this easily with existing iterator and itertools functionality.

If we have a collection as starting point we can do the following which many users should be able to find:

let all_unique = v.iter().unique().count() == v.len();

(So I realized .unique().count() could be more efficient, and #254 does that.)

I was wondering if we should instead add methods to the unique() and unique_by() iterators, but I'm not sure we end up with the right semantics, or what we do if they are called when the unique() is already partially iterated.

Something like this:

let all_unique = collection.iter().unique().all_unique();

or even a method that tells us about both the numbers. The fidelity loss is that the .unique_count() method can not tell us about the dups that were seen before the .unique_count() method was called (if the .unique() was already partially iterated).

let (count_unique, count_dups) = collection.iter().unique().unique_count();

@jswrenn jswrenn self-assigned this Jul 18, 2019
@jswrenn jswrenn added this to the next milestone Dec 26, 2020
Copy link
Member

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay!

bors r+

@jswrenn
Copy link
Member

jswrenn commented Jan 18, 2021

bors r+

Edit: Looks like bors doesn't like it when the repository underlying a PR is deleted. :(

@jswrenn jswrenn merged commit ddeb9f1 into rust-itertools:master Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants