These are chat archives for nrinaudo/kantan.csv

23rd
Feb 2018
jotsif
@jotsif
Feb 23 2018 09:11
Hi there ! I am writing a CSV parser module using the kantan.csv package and wants to write a function like this
   def csvToObject[T <: Product](sep : Char)(row : String): Iterable[T]
Problem is i don't understand the code well enough to figure out how to create an implicit RowEncoder from the type T
Nicolas Rinaudo
@nrinaudo
Feb 23 2018 15:35
I don't think you can do it for T <: Product. Do you not mean for T: Decoder ?
jotsif
@jotsif
Feb 23 2018 15:37
I had hoped that the users of the function csvToObject didn't have to know anything about kantan.csv. But you are probably right
Nicolas Rinaudo
@nrinaudo
Feb 23 2018 15:38
well, users will need to know about kantan.csv at some point, if you mean to write this function for any T
because your csvToObject will need, somehow, to provide a RowDecoder[T].
jotsif
@jotsif
Feb 23 2018 15:51
mmm, got stupid there for a while. It needs to know what case classes I will send in at compile time i guess
Nicolas Rinaudo
@nrinaudo
Feb 23 2018 15:51
yeah, that's pretty much the point
kantan.csv does provide automatic decoder derivation through shapeless though, so your users might just need to know to import kantan.csv.generic._
jotsif
@jotsif
Feb 23 2018 15:52
So I am doing def csvToObject[T : RowEncoder](sep : Char)(row : String): Iterable[T]
exactly
Nicolas Rinaudo
@nrinaudo
Feb 23 2018 15:52
you'll need a RowDecoder, not a RowEncoder
and what you're trying to do looks really similar to what CsvSourceOps provides: http://nrinaudo.github.io/kantan.csv/api/kantan/csv/ops/CsvSourceOps.html
jotsif
@jotsif
Feb 23 2018 15:56
Right
Yes, so csvToObject wraps toCsvReader
jotsif
@jotsif
Feb 23 2018 16:39
But thanks for your help!
Nicolas Rinaudo
@nrinaudo
Feb 23 2018 17:38
I don’t feel I was much help, but do let me know if you get stuck anywhere!