Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Scala sequences have three operators that produce new sequences by adding something to an old sequence: <code>++</code>, <code>+:</code> and <code>:+</code>. The <code>++</code> operator simply concatenates a Scala sequence with another (or a traversable). The other two prepend and append elements, respectively. </p> <p>The peculiar syntax of <code>+:</code> and <code>:+</code> is due to the way they are used. Any operator ending with <code>:</code> applies to the object on the <em>right</em>, not on the left. That is:</p> <pre><code>1 +: Seq.empty == Seq.empty.+:(1) </code></pre> <p>By symmetry, the other operator is <code>:+</code>, though the colon is meaningless in that case. This let you write things like this:</p> <pre><code>scala&gt; 1 +: 2 +: 3 +: Seq.empty :+ 4 :+ 5 :+ 6 res2: Seq[Int] = List(1, 2, 3, 4, 5, 6) </code></pre> <p>Note how the elements being added end up in the exact same position as they appear in the expression. This makes it easier to visualize what's happening.</p> <p>Now, you have <code>:+=</code>, not any of the above. As it happens, Scala allows one to concatenate any operator with <code>=</code> to make up a get-and-set operation. So the common increment expression:</p> <pre><code>x += 1 </code></pre> <p>Actually means</p> <pre><code>x = x + 1 </code></pre> <p>Likewise, </p> <pre><code>v1 :+= "" </code></pre> <p>means</p> <pre><code>v1 = v1 :+ "" </code></pre> <p>which creates a new vector by appending the empty string to the old vector, and then assigns it to <code>v1</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload