++=
can mean two different things in Scala:
1: Invoke the ++=
method
In your example with flatMap
, the ++=
method of Builder
takes another collection and adds its elements into the builder. Many of the other mutable collections in the Scala collections library define a similiar ++=
method.
2: Invoke the ++
method and replace the contents of a var
++=
can also be used to invoke the ++
method of an object in a var
and replace the value of the var
with the result:
var l = List(1, 2)
l ++= List(3, 4)
// l is now List(1, 2, 3, 4)
The line l ++= List(3, 4)
is equivalent to l = l ++ List(3, 4)
.