x ++= y appears to have the same behavior as x = x ++ y
but I cannot find where this behavior is coming form.
It's built into the language. When
x op= y can't be interpreted as a calling the method
op= (because no such method exists in
x's class or any class that it can be implicitly converted to), it's instead interpreted as calling the method
op and an assignment.
(and where is it documented?)
In Scala's language specification, section 6.12.4:
An assignment operator is an operator symbol (syntax category op in Identifiers) that ends in an equals character “=”, with the exception of operators for which one of the following conditions holds:
- the operator also starts with an equals character, or
- the operator is one of (
Assignment operators are treated specially in that they can be expanded to assignments if no other interpretation is valid.
Let's consider an assignment operator such as
+=in an infix operation
l += r, where
rare expressions. This operation can be re-interpreted as an operation which corresponds to the assignment
l = l + r
except that the operation's left-hand-side
lis evaluated only once.
The re-interpretation occurs if the following two conditions are fulfilled.
- The left-hand-side
ldoes not have a member named
+=, and also cannot be converted by an implicit conversion to a value with a member named
- The assignment
l = l + ris type-correct. In particular this implies that l refers to a variable or object that can be assigned to, and that is convertible to a value with a member named
- Where is the `++=` operator defined for a scala immutable list?
- The "--" operator for list subtraction in Scala
- What is the Scala syntax for summing a List of objects?
- What is the scala percent operator (%) and at method for strings do?
- Why is the + operator for List deprecated in Scala?
- Where to put favicon for a scala Spray application (i.e. what is the root of the site?)?
- Scala 2.10 reflection: Why do I get the same type "List()" for the list and list element?
- Where are the test for Scala collections?
- Where are the implicit conversions between Numeric and Double defined in Scala 2.9
- Why does the `is not a member of` error come while creating a list in scala using the :: operator
- When I run "make project" in Intellij 14 for a scala project, where is the jar?
- Monads being a mechanism for sequencing computations, is the below list still a monad though they are printed in a random order Scala
- Compare scala map values to a list and return default value for keys that don't exist in the list
- Scala how to get the key of Map where value as List
- Where is the string operator " <- " defined in Scala?
- Can I define the = operator for my class in Scala
- The type requirement [B >: A] for ++ operator in Scala Lists
- Scala splat operator for only part of parameter list
- How do I write a query for mongodb using the casbah driver for scala that uses a substring and checks if the field is in a list of supplied values?
- Modifying the list while using for comprehension in Scala
- Scala. Need for loop where the iterations return a growing list
- Scala create a List with Future in a for loop and check the result of each Future
- Where is the apply method in the docs, for Scala collection factory objects?
- The identity for the cons operator in scala
- Operator precedence for sum and division on list in Scala
- Difference on concatenation for immutable list between java Guava and Scala
- Getting the first item for a tuple for each row in a list in Scala
- How to reflect concrete return types for methods of classes defined at runtime using the Scala ToolBox?
- Can Scala reflection get you the list of type aliases defined in a class?
- Scala dataframe - where is the spark/ scala dataframe source code for explode on github
More Query from same tag
- Spark S3 access denied when using regex
- How to suppress the "Stage 2===>" from the output console in spark?
- Scala play framework: complex read to match multiple keys for same field in case class
- Scala: groupBy based on boolean applied to next element
- Jackson annotations broken in Scala from 1.9 to 2.1
- Working with ReactiveMongo (for play framework apps) in 2020
- Is there a concept for 'fold with break' or 'find with accumulator' in functional programming?
- SBT: libraryDependencies missing from classpath of jetty-run
- What's the difference between Task and IO in Scalaz?
- Why does RegexTest have a main method?
- How To Convert Scala Case Class to Java HashMap
- Find the first element that satisfies condition X in a Seq
- How to do a parallel flatMapConcat in Akka Streams
- MQTTUtils.createPairedStream() is not a member of org.apache.bahir
- QueryStringBinder for List[String]
- Apache Spark DataFrame apply custom operation after GroupBy
- Cleaning up `case class` with `Option` FIelds
- Is there a way to obtain the "stored" value within a receive definition of an Actor?
- Grabbing process stderr in scala
- I am getting error in eclipse while running Spark WordCount in scala
- Higher kinded type constructor with upper type bounds doesn't work if bound is abstract type member
- (Scala + RxJava3) Flowables.orderedMerge NoSuchMethodError
- How can I use library which is built using 2.9.2 in project which is built using 2.10.1?
- SBT SCALA java.lang.ClassNotFoundException: javax.mail.Authenticator
- Filter Map by key set
- How to set mainClass in ScalaJS build.sbt?
- Loop over a list of objects and display it in lift
- sbt- ManagedStyle.Maven
- How to consume only latest offset in Kafka topic
- scala function return type either or