if (Set(1,2).sameElements(Set(2,1))) then "oh good, sets work" else "curse you #Scala! Foiled again!"
Anyone unfamiliar with the strict definition of this method would think: Of course sets (1,2) and (2,1) "have the same elements"!
But there's no sensible reason to place methods on Iterable which are broken by design on Set.
Checks if the other iterable collection contains the same elements in the same order as this iterable collection.
Note: might return different results for different runs, unless the underlying collection type is ordered.
Note: will not terminate for infinite-sized collections.
Is the inheritance of size equally erroneous for any infinite-sized Iterable?
On Thursday, February 7, 2013 12:38:39 AM UTC-5, Paul Phillips wrote:
But there's no sensible reason to place methods on Iterable which are broken by design on Set.
Well, I wouldn't say this method is necessarily broken by design on Set. If you look past the method's name to its description:
... sameByOrdering. The latter one then should expect an implicit parameter list expecting an ordering that makes this method more general.
It should be changed to sameOrderedElements or even better to sameByOrdering.
"Checks if the other iterable collection contains the same elements in the same order as this general iterable collection .
This comes from `GenIterableLike`. Of course, it is still confusing because of the method name, who would expect this restriction, and moreover its completely uselessness in sub types such as Set?
Note: might return different results for different runs, unless the underlying collection type is ordered."
btw. Set(1,2) == Set(2,1) // equality works
---
On 11 Jul 2013, at 19:48, Chris L wrote:
> the behavior is not even predictable ( Scala version 2.10.2):
> scala> Set(1,2) sameElements Set(2,1)
> res3: Boolean = false
>
> scala> Set(3, 2, 1) sameElements Set(2, 1, 3)
> res2: Boolean = false
>
> scala> Set(3, 2, 1, 4) sameElements Set(2, 1, 4, 3)
> res1: Boolean = false
>
> scala> Set(3, 2, 1, 4, 5) sameElements Set(2, 1, 4, 5, 3)
> res0: Boolean = true
>
> scala> Set(3, 2, 1, 4, 5, 6, 7) sameElements Set(7, 2, 1, 4, 5, 6, 3)
> res4: Boolean = true
>
> any one knows why?
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "scala-debate" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to scala-debate...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
"Si hay reelección, Capriles será reelecto"
--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-debate...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
So, in what situation is 'same iteration' a useful comparison? Is it genuinely used in any places where equality would not be the intended semantics?
In fact, in light of the array example, I am not sure anymore that sameIteration is preferable to sameElements. It avoids the trap mentioned in this thread but makes it so much harder to find for people who want to get an elementwise comparison of arrays.
So, in what situation is 'same iteration' a useful comparison? Is it genuinely used in any places where equality would not be the intended semantics? Is it actually used for non-set collections? It is unclear from the source if two sets with the same elements will in fact have the same iteration order e.g. MySet(1,2,3) and YourSet(1,2,3) could have different iteration orders despite being initialised from the identical sequence of integers.
Generally, it was decided at some point that collection types should capture neither the property of being ordered, nor the property of being finite. Both were tried but as far as I remember led to types that were deemed too complicated.
If we feel this is important enough to change, then I would favor moving sameElements to Seq.
- Chris
On Thu, Jul 11, 2013 at 7:52 PM, Hanns Holger Rutz <con...@sciss.de> wrote:
"Checks if the other iterable collection contains the same elements in the same order as this general iterable collection .
This comes from `GenIterableLike`. Of course, it is still confusing because of the method name, who would expect this restriction, and moreover its completely uselessness in sub types such as Set?
Note: might return different results for different runs, unless the underlying collection type is ordered."
btw. Set(1,2) == Set(2,1) // equality works
I think the original poster in the thread is right. This should be named "sameIteration" not "sameElements".
--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-debate...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.