1

I am currently working on the exercises for Scala at https://www.scala-exercises.org/std_lib/iterables.

The last example illustrates the use of sameElements with these examples

val xs1 = Set(3, 2, 1, 4, 5, 6, 7)
val ys1 = Set(7, 2, 1, 4, 5, 6, 3)
println(xs1 sameElements ys1) //true

and then

val xt1 = Set(1, 2, 3)
val yt1 = Set(3, 2, 1)
println(xt1 sameElements yt1) // false

Why is Set(3, 2, 1, 4, 5, 6, 7) sameElements Set(7, 2, 1, 4, 5, 6, 3) == true, but Set(1, 2, 3) sameElements Set(3, 2, 1) is false? I know that the order of elements matters. But what is the logic behind the order of these sets?

tiefenauer
  • 669
  • 7
  • 19

0 Answers0