Learning Scala from the Scala for Data Science book and the companion Github repo, here I am particularly talking about this function, copied below for reference.
def fromList[T: ClassTag](index: Int, converter: String => T): DenseVector[T] =
DenseVector.tabulate(lines.size) { row => converter(splitLines(row)(index)) }
What does the DenseVector.tabulate(lines.size)
mean between the =
sign and the function body definition? New to scala (with background from python and C++), so cannot figure out if that DenseVector.tabulate(lines.size)
is a local variable of the function being defined (when it should be declared inside the definition) or something else? It cannot be the return type, from what I understand of scala syntax.
Also, is the ClassTag
equivalent to template in C++?
To help you answer the question,
splitLines
has typescala.collection.immutable.Vector[Array[String]]
lines.size
is an unsigned int (obvious, but still making it clear)