Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created June 9, 2014 21:26
Show Gist options
  • Save milessabin/6da04d3ef340171ca2ca to your computer and use it in GitHub Desktop.
Save milessabin/6da04d3ef340171ca2ca to your computer and use it in GitHub Desktop.
Type safe record selection syntax for shapeless records.
scala> import shapeless._, record._, syntax.singleton._
import shapeless._
import record._
import syntax.singleton._
scala> val mary = ('name ->> "Mary" :: 'age ->> 23 :: HNil).record
mary: shapeless.syntax.DynamicRecordOps[shapeless.::[String with shapeless.record.KeyTag[Symbol with shapeless.tag.Tagged[String("name")],String],shapeless.::[Int with shapeless.record.KeyTag[Symbol with shapeless.tag.Tagged[String("age")],Int],shapeless.HNil]]] = DynamicRecordOps(Mary :: 23 :: HNil)
scala> mary.name
res2: String = Mary
scala> mary.age
res3: Int = 23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment