Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line continuation character in Scala

Tags:

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?

like image 596
opensas Avatar asked Sep 08 '12 23:09

opensas


People also ask

How do you type multiple lines in Scala?

Strings in Scala are single lines that are wrapped into double quotes. We can create multiline strings in Scala by surrounding the text with three double quotes or using pipes through a stripMargin(). While creating the multiline string, you can control to maintain the original indentation and formatting.

How do I add a line in Scala?

To write the second line into a new line, write a new line character to the file after the first line. New line character is indicated by "\n". so, you will write "Hello Scala", then "\n" followed by "Bye Scala" to the file.


1 Answers

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) 
like image 95
kiritsuku Avatar answered Mar 06 '23 06:03

kiritsuku