Extract label values from a LabelledGeneric instance

后端 未结 1 1772
耶瑟儿~
耶瑟儿~ 2020-12-16 12:21

Consider the following example:

import shapeless._

case class Foo(bar: String, baz: Boolean)
val labl = LabelledGeneric[Foo]

Now, the type

相关标签:
1条回答
  • 2020-12-16 13:24

    You can obtain the keys of the record (as Symbols) via shapeless.ops.record.Keys.

    This

    import shapeless._
    import shapeless.ops.record._
    
    case class Foo(bar: String, baz: Boolean)
    val labl = LabelledGeneric[Foo]
    val keys = Keys[labl.Repr].apply
    println(keys)
    println(keys.toList.map(_.name))
    

    results in

    'bar :: 'baz :: HNil
    List(bar, baz) : List(String)
    
    0 讨论(0)
提交回复
热议问题