Why aren't map, filter... using infix?


I understand why the explicit “infix” annotation was introduced but wonder why the linq operators for map, filter, group aren’t annotated in the stdlibrary

It makes code using rmore verbose :
val list = (1…3).map({Token()})
instead of val list = 1…3 map {Token()}


The simple reason is that because we don’t believe it improves readability. In your example, you don’t actually need the second pair of parentheses; this is how you should write it:

val list = (1…3).map { Token() }

And we do not believe that replacing the dot before map with a space is an improvement in readability. You do need parentheses around a range, but using a map with a literal range is not so frequent, and is not worth optimizing for.

There are also specific cases where using functions like ‘map’ with infix syntax leads to completely unexpected results in terms of the argument to which the operation is applied.