Hi all,
Recently, I reviewed code with a mix of function literals and other expressions, such as
onComplete { v => p complete { v map f } }
I agree with the syntax to pass function literals as follows:
list map { el => <body> }
It reads very natural, and the function literal is clearly demarcated.
On the other hand, I'd prefer to pass expressions that are *not* function literals to be passed using regular parentheses:
p.complete(v.map(f))
Note that I didn't write `p.complete(v map f)` because
a) I don't think the infix syntax is a good choice for `v map f`, since neither is `f` is a function literal nor is `map` a symbolic operator, and
b) for consistency `p.complete` should be invoked in the same way as `v.map`.
Taken together I'd prefer to express the first example as follows:
onComplete { v => p.complete(v.map(f)) }
What's interesting about this style is that it makes code where function literals appear interspersed with other expressions easy to read:
that onComplete { c => p.complete(c map { (s, _) }) }
The {}'s demarcate function literals, and the ()'s are used to pass non-lambda arguments.
What do you think?
Cheers,
Philipp