Of braces and parentheses

Pavel Fatin

In Scala, you may often want to replace braces with parentheses and vice versa.

For example, imagine that you decided to use curly braces in the following statement:

It looks like not a big deal, but in practice it takes a lot of key presses, cursor positioning, and a fight with the automatic brace balancing. That’s now a thing of the past.

Just invoke an intention (Ctrl + Alt + Enter):

… and it’s done:

It’s possible to run it the other way:


Besides sequence comprehensions, there are similar intentions for converting method call arguments, like the following:

Run the intention:

The result:

Now let’s transform the braces back to parentheses:

Here they are:

Comments below can no longer be edited.

1 Response to Of braces and parentheses

  1. Jem says:

    May 4, 2011

    Is nice!

    Is it possible to convert to squirlies but keep the content inline? i.e.

    `list.foreach(println)` becomes `list.foreach{println}`