I've got a simple recursive function to convert a list of booleans to a string:
def boolsToString(lst: List[Boolean]): String = lst match {
case Nil => ""
case x::xs => x match {
case false => "0" + boolsToString(xs)
case true => "1" + boolsToString(xs)
}
}
This works, but I don't like the repetition of boolsToString. I'd like to do the string concatenation just once (after the case) :
def boolsToString2(lst: List[Boolean]): String = lst match {
case Nil => ""
case x::xs => x match {
case false => "0"
case true => "1"
} + boolsToString2(xs)
}
but this is rejected by the Scala compiler: "';' expected but identifier found."
Is there another way to do the string concatenation just once, after the case?