Answered step by step
Verified Expert Solution
Question
1 Approved Answer
b) Write a tail-recursive polymorphic function with this signature: def countWitheconectx[T](X$: List[T], p: T => Boolean) : Int that returns the number of elements x
b) Write a tail-recursive polymorphic function with this signature: def countWitheconectx[T](X$: List[T], p: T => Boolean) : Int that returns the number of elements x from list xs for which p(x) is true. For example: xal lucky Numbers = List(4, 8, 15, 16, 23, 42) val evenCount = countWithProperty (lucky Numbers, (x: Int) => x % 2 == 0) The value of variable evenCount is 4. c) Write a tail-recursive function with this signature: def scalare.reduct(x: Array[Double], y: Array[Double]) : Double that returns the scalar product of arrays x and y. For example: xal xxes = Array(-1.0, -2, 3) val xxes = Array(2.0, -3, 1) xal prod = scalarproduct(xvec, yves) = // prod == 7 b) Write a tail-recursive polymorphic function with this signature: def countWitheconectx[T](X$: List[T], p: T => Boolean) : Int that returns the number of elements x from list xs for which p(x) is true. For example: xal lucky Numbers = List(4, 8, 15, 16, 23, 42) val evenCount = countWithProperty (lucky Numbers, (x: Int) => x % 2 == 0) The value of variable evenCount is 4. c) Write a tail-recursive function with this signature: def scalare.reduct(x: Array[Double], y: Array[Double]) : Double that returns the scalar product of arrays x and y. For example: xal xxes = Array(-1.0, -2, 3) val xxes = Array(2.0, -3, 1) xal prod = scalarproduct(xvec, yves) = // prod == 7
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started