labelled-generic

Extract label values from a LabelledGeneric instance

非 Y 不嫁゛ 提交于 2019-12-18 03:55:49
问题 Consider the following example: import shapeless._ case class Foo(bar: String, baz: Boolean) val labl = LabelledGeneric[Foo] Now, the type of labl is (prettified) LabelledGeneric[Foo] { type Repr = FieldType[Symbol @@ String("bar"), String] :: FieldType[Symbol @@ String("baz"), Boolean] :: HNil } which already conveys the information I need, i.e. the names of the case class fields. What I'm looking for is a way to go from labl to something along the lines of "bar" :: "baz" :: HNil i.e.

Shapeless - turn a case class into another with fields in different order

帅比萌擦擦* 提交于 2019-12-17 21:52:27
问题 I'm thinking of doing something similar to Safely copying fields between case classes of different types but with reordered fields, i.e. case class A(foo: Int, bar: Int) case class B(bar: Int, foo: Int) And I'd like to have something to turn a A(3, 4) into a B(4, 3) - shapeless' LabelledGeneric comes to mind, however LabelledGeneric[B].from(LabelledGeneric[A].to(A(12, 13))) results in <console>:15: error: type mismatch; found : shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol

Extract label values from a LabelledGeneric instance

∥☆過路亽.° 提交于 2019-11-29 03:11:45
Consider the following example: import shapeless._ case class Foo(bar: String, baz: Boolean) val labl = LabelledGeneric[Foo] Now, the type of labl is (prettified) LabelledGeneric[Foo] { type Repr = FieldType[Symbol @@ String("bar"), String] :: FieldType[Symbol @@ String("baz"), Boolean] :: HNil } which already conveys the information I need, i.e. the names of the case class fields. What I'm looking for is a way to go from labl to something along the lines of "bar" :: "baz" :: HNil i.e. materializing the information contained in the singleton types into a value. Is this possible? I could use a

Shapeless - turn a case class into another with fields in different order

早过忘川 提交于 2019-11-28 17:05:00
I'm thinking of doing something similar to Safely copying fields between case classes of different types but with reordered fields, i.e. case class A(foo: Int, bar: Int) case class B(bar: Int, foo: Int) And I'd like to have something to turn a A(3, 4) into a B(4, 3) - shapeless' LabelledGeneric comes to mind, however LabelledGeneric[B].from(LabelledGeneric[A].to(A(12, 13))) results in <console>:15: error: type mismatch; found : shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("foo")],Int],shapeless.::[shapeless.record.FieldType[shapeless.tag.@@[Symbol,String("bar")],Int]