Please show me how to rewrite toString in a functional way.
The code is ok, but nothing to be proud of, there are 3 temporary variables in it.
class Field(x: Int, y: Int) {
val value = init(x,y)
private def init(x: Int, y: Int) = List.fill(x,y)(new Cell)
override def toString(): String = {
val temp = new StringBuilder
for(i <- value) {
for(j <- i) {
temp.append(j.toString())
}
temp.append("\n")
}
temp.mkString
}
}
Thanks guys!