kantan.csv
kantan.csv copied to clipboard
[Generic] A generic HeaderEncoder with headers?
I noticed in the generic module there is a shapeless based RowEncoder but not one for Header generation. Is there any reason for that. I create a simple one that works for me.
object GenericHeaderEncoder {
implicit def genHeaderEncoder[T, Repr <: HList, Ks <: HList](
implicit gen: LabelledGeneric.Aux[T, Repr],
re: RowEncoder[T],
keys: Keys.Aux[Repr, Ks],
toList: ToList[Ks, Symbol]): HeaderEncoder[T] = new HeaderEncoder[T] {
def rowEncoder: RowEncoder[T] = re
def header: Option[Seq[String]] = Some(keys().toList.map(_.name))
}
}
Note that it still relies on a RowEncoder[T] which can be generated from your generic RowEncoder.
No particular reason, no - I've never needed it so never even realised it was lacking.
Thanks for reporting it and providing an Encoder
implementation! I'll try to work this (and a generic HeaderDecoder
) into the next release.