28 Immutable collections with var

One thing to note is the difference between the +=, +==, -=, -== etc functions regarding mutalbe and immutable collections.

  • For immutable collections - they are not methods of the collection (since it’s not modifiable) but if used on an immutable collection declared with var instead of val then the Scala compier expands them to variable = variable op param. (seel on the left for an example)
  • For mutable collections - they are actually methods on the collection, and they modify the collection when used.

Code editor is using Scalakata.com written by Guillaume Massé