I am trying to learn Shapeless (using version 2.10.2). I have created a very simple extensible record:
val rec1 = (\"foo\" ->> 42) :: HNil
As of shapeless 2.1.0 there is a new syntax to express record types:
scala> :paste
// Entering paste mode (ctrl-D to finish)
import shapeless._
import shapeless.record._
import shapeless.syntax.singleton._
def fun(x: Record.`"foo" -> Int`.T) = x("foo")
// Exiting paste mode, now interpreting.
import shapeless._
import shapeless.record._
import shapeless.syntax.singleton._
fun: (x: shapeless.::[Int with shapeless.labelled.KeyTag[String("foo"),Int],shapeless.HNil])Int
scala> fun( ("foo" ->> 42) :: HNil )
res2: Int = 42
scala> fun( ("foo" ->> 42) :: ("bar" ->> 43) :: HNil )
:30: error: type mismatch;
found : shapeless.::[Int with shapeless.labelled.KeyTag[String("foo"),Int],shapeless.::[Int with shapeless.labelled.KeyTag[String("bar"),Int],shapeless.HNil]]
required: shapeless.::[Int with shapeless.labelled.KeyTag[String("foo"),Int],shapeless.HNil]
fun( ("foo" ->> 42) :: ("bar" ->> 43) :: HNil )
But the Selector is probably the best approach for OP's use-case.