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

sameElements compares the elements, not just the number of elements #18

Closed
davidallsopp opened this issue Mar 6, 2015 · 3 comments
Closed

Comments

@davidallsopp
Copy link
Contributor

http://scala-exercises.47deg.com/koans#iterables says that "sameElements will return true if the two iterables have the same number of elements"

That's a necessary, but not sufficient condition. The elements have to be the same, too. Whether the ordering matters depends on the collection:

scala> List(1,2,3) sameElements List(1,2,3)
res13: Boolean = true

scala> List(1,2,3) sameElements List(3,2,1)
res14: Boolean = false

scala> Set(1,2,3) sameElements Set(3,2,1)
res15: Boolean = false // WHAT?

scala> Set(1,2,3,4,5,6) sameElements Set(6,5,4,3,2,1)
res16: Boolean = true

Also, sameElements for Set produces unexpected results - the behaviour changes depending on the size of the Set, as you can see above! This is arguably a bug in the Scala library: https://groups.google.com/forum/#!topic/scala-debate/je4vZbR3WbA

@rafaparadela
Copy link
Member

Thank you @davidallsopp , I didn't know about this bug. You are reporting several issues. I would like that your contributions gain recognition. Why don't you submit a new "pull request" with your fix for this particular issue?

Thanks a lot, dude!

rafaparadela pushed a commit that referenced this issue Mar 11, 2015
More precise explanation of sameElements, addressing issue #18
@rafaparadela
Copy link
Member

Fixed!

@xaniasd
Copy link

xaniasd commented Aug 13, 2018

The sameElements part of Iterables, in its current form is confusing. I see that the explanation submitted in this PR is missing. Perhaps removed by accident?

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

No branches or pull requests

3 participants