If I have a one liner method that looks like this:
str.toLowerCase.replaceAll("[^\\w']", " ").split(" ").filter(word => word.trim.length >= 1).groupBy(word => word).mapValues(_.size)
What is the best way to avoid long lines of code and split it into multiple lines? Here are the options that I see:
- Assign part of the methods chain to a val and start from line 2 with val.(rest of method chain)
- Move some parts to own methods with meaningful names (
onlyChars
,trimmedText
, ...) - Just split the lines and make the second line nested in the first one