i'm new to Scala and try to work with Options but somehow i still have to set a return value for my method to work. It*s not clear to me why. The code below gets a path parameter that points to a csv file. I want one line of the csv file to be the attributes of an object. Comment shows the problematic line:
import io.Source
case class Example(attribute1: Int, attribute2: Int)
object Example {
def apply(path: String, value1: Int): Option[Example] = {
for {
line <- Source.fromFile(path).getLines()
if line.replaceAll(" ", "").startsWith(value1 + ";")
param = line.split(";")
} {
Some(Example(value1, param(1).toInt))
}
// Why this line??
return None
}
}