Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created December 9, 2012 18:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidandrzej/4246368 to your computer and use it in GitHub Desktop.
Save davidandrzej/4246368 to your computer and use it in GitHub Desktop.
Scala Seq.union behavior - come on!
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)
@rcoh
Copy link

rcoh commented Jul 30, 2015

the confusing bit is that the method is called union? And it doesn't remove duplicates? It seems pretty reasonable otherwise?

@hardproblems
Copy link

is it because Seq is not Set? In any case it is indeed unexpected.

@davidandrzej
Copy link
Author

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