September 2018
Intermediate to advanced
398 pages
9h 43m
English
Our implementation must drop the first line which contains the headers, then for each line, split and create a new instance of EquityData:
package retcalcimport scala.io.Sourcecase class EquityData(monthId: String, value: Double, annualDividend: Double) { val monthlyDividend: Double = annualDividend / 12}object EquityData { def fromResource(resource: String): Vector[EquityData] = Source.fromResource(resource).getLines().drop(1).map { line => val fields = line.split("\t") EquityData( monthId = fields(0), value = fields(1).toDouble, annualDividend = fields(2).toDouble) }.toVector}
This code is quite compact, and you might lose a sense of what types are returned by intermediate calls. In IntelliJ, you can select ...
Read now
Unlock full access