I tried to run the following code and tried to call the function but somehow it didn’t work. Do you know the reason?
def scalarProduct(xs: Vector[Double], ys: Vector[Double]): Double =
What do you mean it doesn’t work?
Doesn’t it compile? If so, which error do you get?
Doesn’t it run? If so, which exception do you get?
Doesn’t it produce the correct output? If so what was the result and what did you expect?
For what I can see that code is correct, maybe you have a problem with your environment setup?
If so, maybe a more interactive channel like the gitter chat would be better?
When you do xs zip ys you get a Vector((Double, Double)). In order to perform map with tuples you need to use case (x,y) in your function. For example,
xs.zip(ys).map{case (x,y) => x * y}.sum
should work. In Scala 3, that necessity has been removed, so you can do it like the way you did it.
Hi, I have created a worksheet in visual studio to see my output immediately. When I put this code I see the the following error message for both underscore _ _