Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a right-associative triple colon operator

Tags:

scala

Although a triple colon is a right-associative operator, the following result says it's not true, is it?

List(3, 4, 5) ::: List(18, 19, 20) //> List[Int] = List(3, 4, 5, 18, 19, 20)

From my point of view, the result should be List(18, 19, 20, 3, 4, 5) since it's the same as saying:

List(18, 19, 20).:::(List(3, 4, 5))

Do I understand the definition of being a right-associative wrong?

like image 498
Alan Coromano Avatar asked Sep 11 '25 00:09

Alan Coromano


1 Answers

From the docs:

def :::(prefix: List[A]): List[A]
[use case] Adds the elements of a given list in front of this list.

Example:

List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4)
prefix  - The list elements to prepend.
returns - a list resulting from the concatenation of the given list prefix and this list.

This says it all. As for the right-associative operations, you're right.

like image 192
4lex1v Avatar answered Sep 13 '25 07:09

4lex1v