These are chat archives for nrinaudo/kantan.csv

13th
Jan 2017
Mike Panciera
@averagehat
Jan 13 2017 20:17
How might I handle a CSV file that will have arbitrary extra columns?
I have a case class that only needs to know about two/three of the columns, which are predictable, but the rest may be just about anything
Mike Panciera
@averagehat
Jan 13 2017 20:23
Ah, #67 happens to work because they happen to be the first few fields. At least I think it will work.
But I might have to add more columns that are out-of-order, so I wonder how I might handle that.
Nicolas Rinaudo
@nrinaudo
Jan 13 2017 21:04
@averagehat are you deriving your decoder instance through the generic module, or do you declare it manually?
Mike Panciera
@averagehat
Jan 13 2017 21:05
Here's my code:
 case class SampleSheetRow(sampleName: String, sampleId: Int)
    implicit val decoder: RowDecoder[SampleSheetRow] = RowDecoder.ordered(SampleSheetRow.apply _)
rawRows = data.readCsv[List, SampleSheetRow](',', true)
Nicolas Rinaudo
@nrinaudo
Jan 13 2017 21:05
right. And you worry that your use case may evolve so that you're not interested in just the first two columns, but maybe just the third and fourth, for instance?
or did I misunderstand your meaning?
Mike Panciera
@averagehat
Jan 13 2017 21:06
that's exactly what I meant
Nicolas Rinaudo
@nrinaudo
Jan 13 2017 21:07
in that case, the RowDecoder.decoder method might be of interest
it expects the index of the cells you're interested in as parameters
case class Car2(make: String, year: Int, model: String, price: Float)
implicit val carDecoder: RowDecoder[Car2] = RowDecoder.decoder(1, 0, 2, 4)(Car2.apply)
is that more or less what you meant?
Nicolas Rinaudo
@nrinaudo
Jan 13 2017 21:15
or did you mean that the index of the cells of interest might change from one row to the next?
that'd be trickier, but still manageable. You'd have to do some manual work though
Mike Panciera
@averagehat
Jan 13 2017 22:10
no, that's right for what I need. Thanks!