Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between List ::: operator and ++

Tags:

What is the difference between scala ::: and ++ operator? According to the doc the behaviour is the same.

like image 310
Lukasz Madon Avatar asked Oct 16 '12 15:10

Lukasz Madon


People also ask

What's the difference between ++ and ::: in Scala?

The difference is in the types that they accept. ::: only accepts a List . ++ accepts is a range of types from [B >: A, That] meaning that ++ will accept a type whose lower bound is List and upper bound is GenTraversableOnce[B] and types in between.

What is the difference between += and in Python?

The difference between both the concatenation operators is that the + creates a new list and the += modifies an existing list in place.

What is ::: in Scala?

The ::: operator in Scala is used to concatenate two or more lists. Then it returns the concatenated list.


1 Answers

They do the same thing, except that ++ can be used with any Traversable and ::: can only be used with lists. Also, methods that end with : are called on the object to the right, so that :::'s argument is the prefix while ++'s argument is the suffix.

like image 188
Kim Stebel Avatar answered Sep 27 '22 23:09

Kim Stebel