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
Get step-by-step solutions from verified subject matter experts
