Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***Utilizing Scala*** Ex. 1: //Complete the following recursive definition of a filter function called myFilter for Scala's builtin List type. //You must not use the

***Utilizing Scala***

Ex. 1:

//Complete the following recursive definition of a "filter" function called "myFilter" for Scala's builtin List type.

//You must not use the builtin "filter" method.

//Your implementation of "myFilter" MUST be recursive.

defmyFilter[A] (xs:List[A], f:A=>Boolean) :List[A] ={

//TODO: Provide definition here.

null

}

Ex. 2:

//Complete the following recursive definition of an "append" function called "my_append" for Scala's builtin List type.

//You must not use the builtin ":::" method.

//Your implementation of "my_append" MUST be recursive.

//HINT: use "::" in the body of the cons-cell case.

defmyAppend[A] (xs:List[A], ys:List[A]) :List[A] ={

//TODO: Provide definition here.

null

}

Ex. 3:

//Complete the following recursive definition of a "flatten" function called "my_flatten" for Scala's builtin List type.

//You must not use the builtin "flatten" method.

//Your implementation of "flatten" MUST be recursive.

//HINT: use either ":::" or your definition of "append" in the body of the cons-cell case.

//EXAMPLE:

//- myFlatten (List ((1 to 5).toList, (6 to 10).toList, (11 to 15).toList)) == (1 to 15).toList

defmyFlatten[A] (xss:List[List[A]]) :List[A] ={

//TODO: Provide definition here.

null

}

Ex. 4:

//Complete the following recursive definition of a "foldLeft" function called "myFoldLeft" for Scala's builtin list type.

//You must not use the builtin "foldLeft" method.

//Your implementation of "foldLeft" MUST be recursive.

//HINT: myFoldLeft ( Nil, e, f) == e

//myFoldLeft (y::ys, e, f) == myFoldLeft (ys, f (e, y), f)

defmyFoldLeft[A,B] (xs:List[A], e:B, f:(B,A)=>B) :B={

//TODO: Provide definition here.

e

}

Please include screenshots of working code and its output!

Thank you!

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions