I would like to enter something like the following match instruction, but formatted across multiple lines. Is that possible in the Scala REPL?
myString match { case patt(a) => true case _ => false }
One way to enter into multi-line mode in the Scala REPL is to hit enter right after the opening curly brace "{", then hit enter after each line until the last closing curly brace has been entered "}". Hitting enter after it will exit the multi-line mode
myScript match { <enter> //enter multi-line mode
| case scriptStart(a) => true <enter>
| case _ => false <enter>
|} <enter> //exit multi-line mode
When cascading transformations, it is as simple as ending each line with a dot. For example:
val wordcount = sc.
textFile("MYFILE.txt").
flatMap( x => x.split(" ") ).
map( w => (w,1) ).
reduceByKey( (a,b) => a+b )
If you're just typing it in as-is, the REPL should detect the opening brace when you return, so that it won't try to parse and execute the code until it finds the closing brace.
You could also use paste mode by typing :pa
or :paste
. This will allow you to enter as much as you want in any format (two blank lines will automatically quit from it). Then when finished entering in code, you can press Ctrl + D to evaluate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With