opensas
opensas

Reputation: 63465

Line continuation character in Scala

I want to split the following Scala code line like this:

ConditionParser.parseSingleCondition("field=*value1*").description 
  must equalTo("field should contain value1")

But which is the line continuation character?

Upvotes: 28

Views: 25129

Answers (1)

kiritsuku
kiritsuku

Reputation: 53348

Wrap it in parentheses:

(ConditionParser.parseSingleCondition("field=*value1*").description 
  must equalTo("field should contain value1"))

Scala does not have a "line continuation character" - it infers a semicolon always when:

  • An expression can end
  • The following (not whitespace) line begins not with a token that can start a statement
  • There are no unclosed ( or [ found before

Thus, to "delay" semicolon inference one can place a method call or the dot at the end of the line or place the dot at the beginning of the following line:

ConditionParser.
parseSingleCondition("field=*value1*").
description must equalTo("field should contain value1")

a +
b +
c

List(1,2,3)
  .map(_+1)

Upvotes: 47

Related Questions