Thursday, March 19, 2020

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

In general:
  • :: - adds an element at the beginning of a list and returns a list with the added element
  • ::: - concatenates two lists and returns the concatenated list
For example:
1 :: List(2, 3)             will return     List(1, 2, 3)
List(1, 2) ::: List(3, 4)   will return     List(1, 2, 3, 4)
In your specific question, using :: will result in list in a list (nested list) so I believe you prefer to use :::.

No comments:

Post a Comment

Recent Post

Databricks Delta table merge Example

here's some sample code that demonstrates a merge operation on a Delta table using PySpark:   from pyspark.sql import SparkSession # cre...