Aqsa Zahoor
Aqsa Zahoor

Reputation: 35

Found Unit but required Double

def Perm_Function(xs: List[(Int,Int)], Dimensions: Int): Double = {
    var sum=0.0
for(i <- 1 to Dimensions)
{
sum=sum+(Perm_help(xs,i))
}
}

i wrote above code but it is giving error: found:Unit required:Double can somebody please help. whats wrong over there?

Upvotes: 0

Views: 110

Answers (1)

pedrorijo91
pedrorijo91

Reputation: 7845

you are not returning anything, just changing the value of sum variable

def Perm_Function(xs: List[(Int,Int)], Dimensions: Int): Double = {

var sum=0.0
for(i <- 1 to Dimensions) {
  sum=sum+(Perm_help(xs,i))
}

sum // return sum

}

a more idiomatic approach would be to write your code as:

def permFunction(xs: List[(Int,Int)], Dimensions: Int): Double = {
  (1 to dimensions).map(dim => permHelp(xs,dim)).sum
}

Upvotes: 2

Related Questions