Question
***Utilizing Scala*** /*You MUST NOT use while loops or (re)assignment to variables (you can use val declarations, * but not var declarations). You must use
***Utilizing Scala***
/*You MUST NOT use while loops or (re)assignment to variables (you can use "val" declarations, * but not "var" declarations). You must use recursion instead. * * You may declare auxiliary functions if you like. * */
concat_list.sc: // Write a function "concatList" that takes a list of strings and concatenates them with a comma between them. // Your function should return the empty string for the empty list. // Your function should return the string when called with a singleton list (list with one element) // For longer lists, e.g., concatList ("a", "b", c") == "a,b,c" // Your function MUST be recursive and MUST NOT use a while loop.
def concatList (xs : List[String]) : String = {
// TODO: Provide definition here. null }
concat_list.test.scala:
import scala.concurrent.Future
import scala.concurrent.duration.Duration
class Tests_concat_list extends munit.FunSuite {
implicit val ec : scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
override val munitTimeout = Duration (1, "s")
import concat_list._
test ("concat_list") {
Future {
assert (concatList (Nil) == "")
assert (concatList (List ("abc")) == "abc")
assert (concatList (List ("abc", "d")) == "abc,d")
assert (concatList (List ("abc", "d", "ef")) == "abc,d,ef")
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started