The Scala List class as an immutable, linear, linked-list class. It’s very efficient when it makes sense for your algorithms to (a) prepend all new elements, (b) work with it in terms of its head and tail elements, and (c) use functional methods that traverse the list from beginning to end, such as
Important note about Seq, IndexedSeq, and LinearSeq
As an important note, I use
Seq in the following examples to keep things simple, but in your code you should be more precise and use
LinearSeq where appropriate. As the
Seq class Scaladoc states:
Just a quick note today that if you split a CSV string in Scala, you should also (immediately) do a
trim on each resulting element in the array. The Scala REPL shows why this is necessary:
Here’s a quick Scala example that shows how to convert multiple spaces in a string to a single space:
Scala String FAQ: How do I split a
String in Scala based on a field separator, such as a string I get from a comma-separated value (CSV) or pipe-delimited file.
Use one of the
split methods that are available on
Perl string trim FAQ: Is there something like a "trim" function in Perl, similar to the Java trim function, which trims leading and trailing whitespace characters from a string?
A Perl trim function
My Perl skills aren't exactly up to date these days, but in days gone past there was no Perl trim function, and somewhere along the way I wrote one. Here's the source code for my Perl trim function: