0

I'm brand new to shapeless and I would like to transform a Mapper[mix.type, HNil]#Out to a case class

How can I do this? (Let me know if you need more infos...)

Simon
  • 6,025
  • 7
  • 46
  • 98

1 Answers1

1

That would only work if you define a case class that has the exact same shape that this Mapper#Out. If that's the case, you can create an instance of your case class using shapeless.Generic:

val mout = ... // HList coming from your Mapper
case class A(i: Int, s: String)
shapeless.Generic[A].from(mout): A

That's assuming Generic#Repr and Mapper[mix.type, HNil]#Out are the same type, which you can check using the following:

val mapper = the[Mapper[mix]]
val gen    = the[Generic[A]]
implicitly[mapper#Out =:= gen#Repr] // This only complies if scalac can
                                    // prove equality between these types
OlivierBlanvillain
  • 7,701
  • 4
  • 32
  • 51
  • It works, thanks. (I had tried this but since IntelliJ saw it as an error I thought it wouldn't compile and didn't go further) – Simon Apr 28 '17 at 15:25