Triple colon Scala

Scala

Scala Problem Overview


I'm trying to pick up some scala. Reading through examples I came across this impossible-to-google nugget:

case 3 => l ::: List(3)

What does the triple colon accomplish?

Scala Solutions


Solution 1 - Scala

Concatenates two lists - javadoc

Solution 2 - Scala

To add to gkamal's answer, it's important to understand that methods whose names end in a colon are right-associative. So writing l ::: List(3) is the same as writing List(3).:::(l). In this case it doesn't matter since both operands are lists, but in general you'll need this knowledge to find such methods in the scaladocs.

It also helps to know that the scaladocs have a comprehensive index of all methods (and classes, etc) with symbolic names. You can reach it by clicking on the # in the upper-left corner.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionprovidenceView Question on Stackoverflow
Solution 1 - ScalagkamalView Answer on Stackoverflow
Solution 2 - ScalaAaron NovstrupView Answer on Stackoverflow