0

I have defined a function that receives an array of arrays. I want to get the sum of all arrays. My question is how to make that sum.

def suma[T](args: WrappedArray[T]*)(implicit n: Numeric[T]) = {
    args.transpose.map(_.sum)
} 
def sum[T](arr: WrappedArray[WrappedArray[T]])(implicit n: Numeric[T]) = {
    val result = suma( ______ )
}

I thought I use the defined "sum" , but not how to pass the contents of the container array. Like there is a much simpler way to do this. Any ideas?

1 Answer 1

2

To get "sum of all arrays" you want .flatten, not .transpose. args.flatten.sum should do it.

Or are you asking how to call a function with vargargs? For that, you need a splat operator: val result = suma(arr:_*)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.