Question: USING SCALA Write a function called conditional that takes a value x and two functions, p and f, and returns a value of the same

USING SCALA

Write a function called conditional that takes a value x and two functions, p and f, and returns a value of the same type as x. The p function is a predicate, taking the value x and returning a Boolean b. The f function also takes the value x and return a new value of the same type. Your conditional function should only invoke the function f(x) if p(x) is true, and otherwise return x. Then explain how many type parameters will the conditional function require?

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!