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

[Suggestion] Make another Combination iterator #330

Open
fyrchik opened this issue Feb 2, 2019 · 0 comments · May be fixed by #403
Open

[Suggestion] Make another Combination iterator #330

fyrchik opened this issue Feb 2, 2019 · 0 comments · May be fixed by #403

Comments

@fyrchik
Copy link
Contributor

fyrchik commented Feb 2, 2019

Current implementation makes it hard to iterate over all combinations of infinite iterator.
E.g. every element from (1..).combinations(3) will always start with [1,2,...] so there is no way to ever get [2,3,4].

But there is another way to implement this:

  1. Iterate over all combinations which uses only indices < n (in lexicographic order).
  2. Iterate over the rest.

This way our example will be [1,2,3], [1,2,4], [1,3,4], [2,3,4], [1,2,5], ...

It is practical to also have this implementation alongside with current.
I can make a PR.

EDIT: This is similar to #293 (but not the same).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant