Scala list concatenation, ::: vs ++ -


is there difference between ::: , ++ concatenating lists in scala?

scala> list(1,2,3) ++ list(4,5) res0: list[int] = list(1, 2, 3, 4, 5)  scala> list(1,2,3) ::: list(4,5) res1: list[int] = list(1, 2, 3, 4, 5)  scala> res0 == res1 res2: boolean = true 

from the documentation looks ++ more general whereas ::: list-specific. latter provided because it's used in other functional languages?

legacy. list defined functional-languages-looking:

1 :: 2 :: nil // list list1 ::: list2  // concatenation of 2 lists  list match {   case head :: tail => "non-empty"   case nil          => "empty" } 

of course, scala evolved other collections, in ad-hoc manner. when 2.8 came out, collections redesigned maximum code reuse , consistent api, can use ++ concatenate any 2 collections -- , iterators. list, however, got keep original operators, aside 1 or 2 got deprecated.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -