In Scala, I can make a caseclass, case class Foo(x:Int), and then put it in a list like so:
case class Foo(x:Int)
List(Foo(42))
Now, nothing strange
It ends with a :. And that is the sign, that this function is defined in the class to the right (in List class here).
:
List
So, it's List(Foo(2)).::(Foo(40)), not Foo(40).::(List(Foo(2))) in your example.
List(Foo(2)).::(Foo(40))
Foo(40).::(List(Foo(2)))