Some answers to questions that you did ask, and some answers to questions you didn’t ask
So my question is, why my function is returning List[Any] instead of List[Double] or List[List[Double]]
A method only has one return type. Your method returns a List[Double] from one branch, and a List[List[Double]] from the other branch. The lowest upper bound (LUB) of those two types is List[Any] and that’s what you get.
When is it detemined what the return type of a method is? Does leaving off the return type of a method mean it has a dynamic return type?
This is resolved at compile time. That you left off the return type doesn’t mean there is no statically known return type, just that you said to the compiler to figure it out for you.
I want to sum up the return value from the function using map(._, sum) , how can I do that
the mapmethod only takes one parameter, so I don’t understand exactly what you want to do and return