kantan.csv icon indicating copy to clipboard operation
kantan.csv copied to clipboard

[Generic] A generic HeaderEncoder with headers?

Open kailuowang opened this issue 7 years ago • 1 comments

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.

kailuowang avatar Jan 26 '18 18:01 kailuowang

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.

nrinaudo avatar Jan 26 '18 21:01 nrinaudo