-
Notifications
You must be signed in to change notification settings - Fork 21
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
Combinations doesn't handle duplicate elements #12540
Comments
does scala/scala#9942 shed any light on this for you? cc @counter2015 |
with implementation at https://www.scala-lang.org/api/current/scala/collection/Seq.html#combinations(n:Int):Iterator[C] It appears that, of the many uses of underscore, emphasis is not one.
|
I see @SethTisue is up to his usual hijinks, with the emphasis on jinx. The recent update didn't touch |
The updated docs makes it more in line with the current behavior, but I wonder if this is the most intuitive implementation? It's a rather surprising behavior, that only the first occurrence is considered for ordering purposes. Ex, python implementation is more intuitive imo
|
@arminsumo thanks for the heads up about expectations. I'll submit a doc tweak before I forget what I just learned. |
PR that documents the status quo: scala/scala#9947 That still leaves the question of whether the behavior should change. Not sure we can change the behavior in a 2.13.x point release, since it would be a design change and not merely fixing a "bug"? |
If only there were a repo where contributors could add functionality. Oh I see people do add issues at https://github.com/scala/scala-library-next/issues Offhand, I can imagine 3 flavors:
|
I prefer multiset result. Mathematically speaking, combinations should not care about order. Order is the thing that permutation should care.
However, in real world, when we compute a large number's combinations, it's better to use iterator rather than set which This will introduce the concept of order. And the multiset result is not as easy to read or use than sequence result. |
reproduction steps
using Scala 2.13,
https://scastie.scala-lang.org/V3sDnjcJTTSjVq3nfKXLzA
problem
Combinations method does not seem to gracefully handle input with duplicated elements. The output does not represent an ordered combination of the input, as the docs suggest it should do
The text was updated successfully, but these errors were encountered: