Reputation: 1
I am trying understand some Scala code I was given to debug, and why it does not work as expected. (p.s. newbe alert wrt Scala).
case class ColNmbr(colNmbr: Int)
def getValidColumns(m: Matrix): List[ColNmbr] = {
var l1 = matrix.zipWithIndex
var l2 = l1.filter(tp => !checkCol(tp._1)).map(_._2)
println("result:" + l2)
l2
}
Matrix is just a List of Lists.
The code is supposed to return a list of column indexes of all matrix columns that pass a validity check which returns a boolean. The data is correct as at the println, but there is a type error because l2 is a List[Int] instead of a List[ColNmbr]. I cannot change the case class, so how do I get the types to match?
Upvotes: 0
Views: 89
Reputation: 7865
case class ColNmbr(colNmbr: Int)
def getValidColumns(m: Matrix): List[ColNmbr] = {
var l1 = matrix.zipWithIndex
var l2 = l1.filter(tp => !checkCol(tp._1)).map(_._2)
println("result:" + l2)
l2.map(ColNmbr)
}
Upvotes: 1