Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Last active August 29, 2015 14:07
Show Gist options
  • Save kevinwright/a162cbb28056f7efe40f to your computer and use it in GitHub Desktop.
Save kevinwright/a162cbb28056f7efe40f to your computer and use it in GitHub Desktop.
Exploring LabelledGeneric
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