My requirement is to read csv file from src-resourses folder and convert them to DF .My code is as below. Genre and month are case class am using this to give structure to my list so that I can convert them to DF .In the below code in the place of _ what should I use so that I can get List[Genre] or List[Month] based on the fileName value which am going to pass.
trait IndexReader[T] {
def read(filePath: String, sep: String,fileName:String): List[T] = {
val stream: InputStream = getClass.getResourceAsStream("/" + filePath)
val lines: Iterator[String] = scala.io.Source.fromInputStream(stream).getLines
lines.map(line => {normalize(line, sep,fileName)}).toList
}
def normalize(line: String, sep: String,fileName:String): T
}
class BrandReader extends IndexReader[_] {
override def normalize(line: String, sep: String,fileName:String):_ = {
val lineSplit: Seq[String] = line.split(sep).toList
val file = fileName match {
case "indexGenre" => Genre(lineSplit(0), lineSplit(1))
case "indexMonth" => Month(lineSplit(0), lineSplit(1))
}
file
}
}