Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

Find a standard form of the given equation. y = 3x -4

Answered: 1 week ago

Question

=+4 Develop and deliver the CCT program.

Answered: 1 week ago

Question

=+5 Evaluate whether the CCT program was effective.

Answered: 1 week ago

Question

=+Identify the type of global assignment for which CCT is needed.

Answered: 1 week ago