3 ms·
> ::, :::, ++, :+, ++:, +: > Can any non-scala programmer guess which one is which? I have read the documentation and I still do not know which one is which.
by finnw 15y ago
> ::, :::, ++, :+, ++:, +:
> Can any non-scala programmer guess which one is which?
I have read the documentation and I still do not know which one is which.
Specifically the summary documentation is the same for both ++ and ++:
Can you explain the difference to a non-scala programmer? I can see that the answer must be in the type signatures, but I have no idea how to decipher those.
- soc88 15y agoEasy. The first one returns the collection type of the left collection, the second one the type of the right collection. Appending : to a method name makes makes the method right-associate. That's a very general rule, nothing to do with collections ...
- zohebv 15y agoIn scala the use of : changes the associativity of the operator, so a ++ b ++ c is equivalent to (a.++ b).++ c while a ++: b ++: c is equivalent to (c.++: b).++: a However fear not :-) the arguments are always evaluated left to right i.e. a,b,c and never c,b,a. It might be useful to think of (c.++: b).++: a as a ++ (b ++ c) except that ++ has c as the "this" parameter in the inner expression and not b.