You're right. Understanding is syntactic sugar. I find that the basic methods are more concise and easier to read as soon as you get used to them.
Compare the following equivalent statements:
1. for (i <- 1 to 100; if (i % 3 == 0)) yield Math.pow(i, 2) 2. (1 to 100).filter(_ % 3 == 0).map(Math.pow(_, 2))
In my opinion, adding a semicolon to # 1 detracts from the fact that this is a simply connected statement. There is also a feeling that I am var (is it 1, or 99, or is there something in between?) That detracts from the functional style otherwise.
Option 2, obviously, is a chain of method calls for objects. Each link in the chain clearly states its responsibility. There are no intermediate variables.
Perhaps understanding is included as a convenience for developers migrating from Java. Whatever is chosen is a matter of style and preference.
Synesso Sep 06 '09 at 23:09 2009-09-06 23:09
source share