4 ms·
Does Scala have line continuation? I got really used to pipes from R (which I guess come from F#/Elixir), which in turn got me really comfortable with multi-lin
by nerdponx 10y ago
Does Scala have line continuation? I got really used to pipes from R (which I guess come from F#/Elixir), which in turn got me really comfortable with multi-line statements like:
foo = baz.\
list().\
filter{ bar => condition(bar) }.\
map(transform(_)).\
toList
IMO this is about as readable as it gets. It's like bullet points enumerating each step in the "algorithm" that produces a `foo`.
AFAIK Javascript also uses this pattern a lot.
- uiri 10y agoI think that Scala uses semicolon terminated lines so you would write something like: foo = baz .list() .filter{ bar => condition(bar) } .map(transform(_)) .toList;
- djsumdog 10y agoScala doesn't require the semi-colon at the very end, but it does allow for them if you really want two statements on the same line. Edit: and yes, that line separation works fine, both compiled and in the REPL.