In a lot of Scala examples I see people use curly braces in places I find outright strange, when the same statement could easily be written using parentheses.
Example:
lst foreach (x => println(s"the value returned is: $x")) // parens
lst foreach {x => println(s"you get the idea, $x")} // braces
I understand that you can use braces as an alternative to parentheses, simply because it allows you to write a statement on multiple lines:
val res = for {
x <- coll1
y <- coll2
} yield (x, y)
- So when it's written on a single line, is there any inherent reason to use one over the other?
- The outcome should be the same in the end, or am I missing something?
- Or is it simply just a matter of style and/or personal taste?