Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Generic] A generic HeaderEncoder with headers? #139

Open
kailuowang opened this issue Jan 26, 2018 · 1 comment
Open

[Generic] A generic HeaderEncoder with headers? #139

kailuowang opened this issue Jan 26, 2018 · 1 comment

Comments

@kailuowang
Copy link

kailuowang commented Jan 26, 2018

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.

@nrinaudo
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants