These are chat archives for nrinaudo/kantan.csv

10th
Apr 2018
Victor Viale
@Koroeskohr
Apr 10 2018 10:42
hello :) got a quick question, I'm decoding a piece of csv with a date, but I'd like to have that date wrapped in a case class with an underlying value, and it currently doesn't want me to (missing CellDecoder for said case class), is there a classy way to do this ? thanks a lot :)
Nicolas Rinaudo
@nrinaudo
Apr 10 2018 11:20
So you want to have something like:
final case class DateWrapper(value: ZonedDateTime)
right?
Assuming that you have a CellDecoder[ZonedDateTime], or whatever date / time type you're using, you can easily declare a new one for DateWrapper:
implicit val dateWrapperCellDecoder: CellDecoder[DateWrapper] = CellDecoder[DateWrapper].map(d => DateWrapper(d))
Victor Viale
@Koroeskohr
Apr 10 2018 11:35
That's what I thought. I guess there's no way to make this process generic for any case class with a date underlying value ?
Nicolas Rinaudo
@nrinaudo
Apr 10 2018 12:33
Sure, with the generic module, it’s in the documentation
In a meeting right now, but if you can’t find it I’ll get you a link later
Victor Viale
@Koroeskohr
Apr 10 2018 12:51
I'm sorry, I'm not exactly good at generics yet, I don't quite get everything yet :) thanks for your time by the way
there's not much to understand, it's basically automatic
it's just... it's automatic for everything, so be careful, you might be getting decoders and encoders for types for which you might have wanted to declare generic ones
Victor Viale
@Koroeskohr
Apr 10 2018 13:13

All case classes of arity 1 have CellDecoder and CellEncoder instances, provided the type of their single field also does.

This should mean I should already have what I want, right ? I have both java8 and generics imports

Nicolas Rinaudo
@nrinaudo
Apr 10 2018 13:15
well, do you have a decoder for your date time type?
Victor Viale
@Koroeskohr
Apr 10 2018 13:18
Oh, I assumed implicits were already provided, well that solves this mystery
I'll get to that, thanks a lot
Nicolas Rinaudo
@nrinaudo
Apr 10 2018 13:19
that depends on the type. Since I don't know what date time type you're using, I don't know whether there's a default instance for it
Victor Viale
@Koroeskohr
Apr 10 2018 13:19
LocalDate
Nicolas Rinaudo
@nrinaudo
Apr 10 2018 13:19
from? joda or java8?
Victor Viale
@Koroeskohr
Apr 10 2018 13:19
java8
Victor Viale
@Koroeskohr
Apr 10 2018 13:20
Oh I get it, I need to declare the implicit myself because of the formatter
Nicolas Rinaudo
@nrinaudo
Apr 10 2018 13:21
depends, there is a de fault format, ISO 8601, but you still need to import it
Seriously, it's all in the documentation.
Victor Viale
@Koroeskohr
Apr 10 2018 13:22
Apologies, I read that too quickly
Nicolas Rinaudo
@nrinaudo
Apr 10 2018 13:23
No worries.
The code works - it needs to be compiled and ran to generate the documentation - so if this looks like it does what you need it to do, then it's supported.