I'm pretty new to Scala programming and now trying to understand the exact behavior of the operator + for the scala.collection.immutable.List. Here is what I wrote:
val _1 = List(1, 2) println((_1 + "2") foreach print I couldn't write the following
_1 + 2 //error: expected String That's clear, because we're trying to execute the + operator defined within the String class.
But what is not clear it's why they didn't just override the operator + for the List, but instead defined operator ++ for concatenating?
Was there some technical reason for that?
What does that mean?
+attached toStrings.+operator. And what you want would be:+instead of+or++.+for everything convertible toString. So theListis first converted toStringand then there is a+operator.+operator to theList-like data structure is just a bad habit as the+operation in mathematics is commutative, butListnor evenStringis not.