shadedshapeless
LabelledGeneric is similar to Generic, but includes information about field names or class names in addition to the raw structure.
Continuing the example from shadedshapeless.Generic, we use LabelledGeneric to convert an object to an shadedshapeless.HList:
scala> val lgenDog = LabelledGeneric[Dog] lgenDog: shadedshapeless.LabelledGeneric[Dog]{ type Repr = Record.`'name -> String, 'bonesHidden -> Int`.T } = ... scala> lgenDog.to(odie) res15: lgenDog.Repr = odie :: 3 :: HNil
Note that the representation does not include the labels! The labels are actually encoded in the generic type representation using shadedshapeless.Witness types.
As with shadedshapeless.Generic, the representation for Animal captures the subclass embedding rather than the fields in the class, using shadedshapeless.Coproduct:
scala> val lgenAnimal = LabelledGeneric[Animal] lgenAnimal: shadedshapeless.LabelledGeneric[Animal]{ type Repr = Union.`'Cat -> Cat, 'Dog -> Dog`.T } = ... scala> lgenAnimal.to(odie) res16: lgenAnimal.Repr = Dog(odie,3) scala> genAnimal.to(odie) match { case Inr(Inl(dog)) => dog ; case _ => ???} res19: Dog = Dog(odie,3)
the type which this instance can convert to and from a labelled generic representation
The generic representation type for {T}, which will be composed of {Coproduct} and {HList} types
Convert an instance of the generic representation to an instance of the concrete type
Convert an instance of the concrete type to the generic value representation
LabelledGeneric is similar to Generic, but includes information about field names or class names in addition to the raw structure.
Continuing the example from shadedshapeless.Generic, we use LabelledGeneric to convert an object to an shadedshapeless.HList:
Note that the representation does not include the labels! The labels are actually encoded in the generic type representation using shadedshapeless.Witness types.
As with shadedshapeless.Generic, the representation for Animal captures the subclass embedding rather than the fields in the class, using shadedshapeless.Coproduct:
the type which this instance can convert to and from a labelled generic representation