Last active
August 29, 2015 14:07
-
-
Save kevinwright/a162cbb28056f7efe40f to your computer and use it in GitHub Desktop.
Exploring LabelledGeneric
This file contains 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 Wibble(x: Int, y: String) | |
val wib = Wibble(42, "towel") | |
val gen = LabelledGeneric.product[Wibble] | |
// shapeless.LabelledGeneric[Wibble]{type Repr = shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("x")],Int],shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("y")],String],shapeless.HNil]]} = $1$$1@56670aec | |
:t gen | |
//shapeless.LabelledGeneric[Wibble]{type Repr = shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("x")],Int],shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("y")],String],shapeless.HNil]]} | |
val out = gen.to(wib) | |
// out: gen.Repr = 42 :: towel :: HNil | |
:t out | |
//gen.Repr | |
def toRepr[T <: Product](obj: T)(implicit lg: LabelledGeneric[T]) = lg.to(obj) | |
toRepr(wib) | |
// shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("x")],Int],shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("y")],String],shapeless.HNil]] = 42 :: towel :: HNil | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment