Create lenses for HList and use Generic (shapeless) to define Iso between case classes and HList #15

Closed
julien-truffaut opened this Issue Feb 26, 2014 · 4 comments

Projects

None yet

2 participants

@julien-truffaut
Owner

No description provided.

@julien-truffaut
Owner

Any one knows how can I get an implicit of Generic.Aux[S, L] when S is a case class and L and HList?

@milessabin If you have a min, your help will be great :)

@puffnfresh

@julien-truffaut I think it's something like this:

def toHList[A <: Product](a: A)(implicit g: Generic[A]): g.Repr = g.to(a)
def fromHList[A <: Product, H <: HList](a: H)(implicit g: Generic.Aux[A, H]): A = g.from(a)
@julien-truffaut
Owner

@puffnfresh Thanks, I managed to create a method that generates a lens toward any element of a case class (mainly taken from shapeless lens) but I still need to use Generic.product on the case class to generate an implicit https://github.com/julien-truffaut/Monocle/blob/hlist-lens/examples/src/main/scala/monocle/HListExample.scala#L26

I also found another problem, overloading compose seems to cause an issue with complex lenses (see line 34).

@julien-truffaut
Owner

Added lenses for HList and for any class that have an HList representation.
There are some issues between type inference and overloaded compose method, so I had to create an alias to compose which is restricted to lens composition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment