Last active
October 16, 2018 04:01
-
-
Save LMnet/bb547ba5b10e3424ac7b7515c4d875d5 to your computer and use it in GitHub Desktop.
LabelledGeneric based keys descriptions
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
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