Skip to content

Instantly share code, notes, and snippets.

@jonifreeman
Created September 15, 2013 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonifreeman/6570276 to your computer and use it in GitHub Desktop.
Save jonifreeman/6570276 to your computer and use it in GitHub Desktop.
Explicit type for a Shapeless record, version: type FieldType[K, V] = (K, V)
// See https://gist.github.com/jonifreeman/6533463
object TestExplicitRecordType {
import shapeless._, record._, syntax.singleton._
object testF extends Poly1 {
implicit def atFieldType[K, V] = at[(K, V)] {
case (k, v) => k.toString
}
}
// Is there more straighforward way to give an explicit type for a record?
val k1 = Witness("k1")
val k2 = Witness("k2")
type Error = (k1.T, String) :: (k2.T, Long) :: HNil
// That seems to work...
val err1 = "k1" ->> "1" :: "k2" ->> 1L :: HNil
val err2: Error = "k1" ->> "1" :: "k2" ->> 1L :: HNil
// ... and getting the key works too since no need for Witness.Aux
testF(err1.head) // OK
testF(err2.head) // OK
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment