No good idea about the concern of reversing the list twice. But you may
letLet you inner function return a List instead of a string thus having less conversions from list to string and string to list.
changeChange your match to the following pattern (not tested):
case " " :: tail => removePreString(tail) case _ => _
case " " :: tail => removePreString(tail) case _ => _
I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A]def dropWhile(p: (A) ⇒ Boolean): List[A]
which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...
No good idea about the concern of reversing the list twice. But you may
let you inner function return a List instead of a string thus having less conversions from list to string and string to list.
change your match to the following pattern (not tested):
case " " :: tail => removePreString(tail) case _ => _
I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A] which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...
No good idea about the concern of reversing the list twice. But you may
Let you inner function return a List instead of a string thus having less conversions from list to string and string to list.
Change your match to the following pattern (not tested):
case " " :: tail => removePreString(tail) case _ => _
I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A]
which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...
No good idea about the concern of reversing the list twice. But you may
let you inner function return a List instead of a string thus having less conversions from list to string and string to list.
change your match to the following pattern (not tested):
case " " :: tail => removePreString(tail) case _ => _
I just realize you could also use on a list def dropWhile(p: (A) ⇒ Boolean): List[A] which drops longest prefix of elements that satisfy a predicate. You could then chain dropWhile not a space | reverse | dropwhile not a space | reverse...