Using Scala 2.10.3. The following code works for me:
val sequence = new ListBuffer[Int]() sequence.+=:(x)
but if I write:
val sequence = new ListBuffer[Int]() sequence +=: x
I get:
value +=: is not a member of Int sequence +=: x ^
What am I missing?
Any statement ending in :is right-associative.
:
So when you write:
sequence +=: x
It is analyzed as:
x.+=:(sequence)
Which, of course, fails because it xdoes not have a method+=:
x
+=:
In Scala, methods ending with a colon are called in the right argument instead of the left, so your second example
which fails because it Intdoes not have such an operator.
Int
+=:is a preend operator (for example, ::for immutable lists), so it makes sense to be correct associative
::
1 +=: 2 +=: 3 +=: ListBuffer() += 4 += 5 += 6 // ListBuffer(1, 2, 3, 4, 5, 6)