Created
December 19, 2017 19:49
-
-
Save Jacoby6000/6701e0ebd47b52e87ed09ac0de018471 to your computer and use it in GitHub Desktop.
Doobie Shapeless Based Value Class Encoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| case class Foo(a: Int) | |
| implicit val fooMeta: Meta[Foo] = valueClassMeta[Foo].apply | |
| private def valueClassMeta[A]: PartiallyAppliedValueClassMeta[A] = new PartiallyAppliedValueClassMeta[A] | |
| private class PartiallyAppliedValueClassMeta[A] { | |
| def apply[L <: HList, S]( | |
| implicit ev: Generic.Aux[A, L], | |
| toL: (S :: HNil) =:= L, | |
| toS: L =:= (S :: HNil), | |
| tt: TypeTag[A], | |
| meta: Meta[S] | |
| ): Meta[A] = | |
| Meta[S].xmap[A](s => ev.from(toL(s :: HNil)), a => toS(ev.to(a)).head) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment