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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!