Skip to content

Instantly share code, notes, and snippets.

@LMnet
Last active October 16, 2018 04:01
Show Gist options
  • Save LMnet/bb547ba5b10e3424ac7b7515c4d875d5 to your computer and use it in GitHub Desktop.
Save LMnet/bb547ba5b10e3424ac7b7515c4d875d5 to your computer and use it in GitHub Desktop.
LabelledGeneric based keys descriptions
import shapeless._
import shapeless.record._
case class User(
id: Long,
name: String,
age: Int
)
val user = User(15L, "Test", 25)
val gen = LabelledGeneric[User]
val repr = gen.to(user)
val keys = repr.keys
object mapper extends Poly1 {
implicit val id = at[Witness.`'id`.T](_ => "This is id")
implicit val name = at[Witness.`'name`.T](_ => "This is name")
implicit val age = at[Witness.`'age`.T](_ => "This is age")
}
keys.map(mapper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment