Created
August 6, 2013 16:26
-
-
Save milessabin/6166101 to your computer and use it in GitHub Desktop.
Encoding records in #Scala as an HList of values tagged with the singleton types of their keys.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import SingletonTypes._ ; import Record._ | |
import SingletonTypes._ | |
import Record._ | |
scala> val r = "name" ->> "foo" :: "age" ->> 1 :: "lastName" ->> "bar" :: HNil | |
r: shapeless.::[String with Object{type keyType = String("name")},shapeless.::[Int with Object{type keyType = String("age")},shapeless.::[String with Object{type keyType = String("lastName")},shapeless.HNil]]] = foo :: 1 :: bar :: HNil | |
scala> r(0) | |
res0: String with Object{type keyType = String("name")} = foo | |
scala> r(1) | |
res1: Int with Object{type keyType = String("age")} = 1 | |
scala> r(2) | |
res2: String with Object{type keyType = String("lastName")} = bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment