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

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

Comments

@julien-truffaut
Copy link
Member

No description provided.

@julien-truffaut
Copy link
Member Author

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
Copy link
Contributor

@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
Copy link
Member Author

@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 added a commit that referenced this issue Mar 16, 2014
@julien-truffaut
Copy link
Member Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants