Created
December 9, 2012 18:25
-
-
Save davidandrzej/4246368 to your computer and use it in GitHub Desktop.
Scala Seq.union behavior - come on!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> val x = Seq(1,2) | |
x: Seq[Int] = List(1, 2) | |
scala> val y = Seq(2,3) | |
y: Seq[Int] = List(2, 3) | |
scala> x.union(y) | |
res0: Seq[Int] = List(1, 2, 2, 3) |
is it because Seq is not Set? In any case it is indeed unexpected.
Yeah IMO union
is pretty suggestive naming for this method which would lead me to believe it had Set.union
semantics. The Scala collection docs finesse this by saying Seq.union
is multiset-union, but I guess it would surprise me especially if IntelliJ autocomplete helped me call union
on a datatype which I didn't explicitly realize to be Seq
...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the confusing bit is that the method is called union? And it doesn't remove duplicates? It seems pretty reasonable otherwise?