Scala lambda style (x) => {...} vs { (x) => ... } -


i'm new scala , reading sample code using rescala. in code, appears author uses 2 styles define lambdas:

  1. { x => println(x) }
  2. (x => { println(x) })

i assume these 2 styles semantically equivalent. think second style allows easy addition of additional statements in lambda body.

is correct? way more "idiomatic"? interesting whether {} opens new lexical scope (like in c) or not.

i assume these 2 styles semantically equivalent.

yes

however think second style allows easy addition of additional statements in lambda body.

no. or, rather, yes, first style.

which way more "idiomatic"?

this opinion-based. opinions vary.

it interesting whether {} opens new lexical scope (like in c) or not.

yes do.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -