- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why do I have to use a different syntax for lists and streams in Scala? More precisely, why is it impossible to implement :: and ::: operations for the Stream class?
Created by admin on 2008-07-28.
Updated: 2008-07-28, 16:36
The :::
operator is already used for List
concatenations, like in List(1,2,3) ::: List(4,5,6)
gives List(1,2,3,4,5,6)
.
Also, we had to make a choice on which operators become right-associative. We chose that everything that ends in a ":" would be so, which means that a ::: b ::: c
is translated to method calls c.:::(b).:::(a)
. Since streams are usually infinite, it would not make much sense to use right-associative operations in this way, so one would need to use another character as the last character, for example ::+