Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Created December 19, 2017 19:49
Show Gist options
  • Select an option

  • Save Jacoby6000/6701e0ebd47b52e87ed09ac0de018471 to your computer and use it in GitHub Desktop.

Select an option

Save Jacoby6000/6701e0ebd47b52e87ed09ac0de018471 to your computer and use it in GitHub Desktop.
Doobie Shapeless Based Value Class Encoder
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