Hacker News new | ask | show | jobs
by finnw 5315 days 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.

2 comments

In 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.
Easy. 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 ...