Skip to content

Instantly share code, notes, and snippets.

@charmby
Created August 21, 2019 08:12
Show Gist options
  • Save charmby/14a4af53527f4a2e38b9bbc322e0940d to your computer and use it in GitHub Desktop.
Save charmby/14a4af53527f4a2e38b9bbc322e0940d to your computer and use it in GitHub Desktop.
import shapeless._
case class MyClass(field1: String, field2: Int)
def fieldName[A](fieldKey: Witness.Lt[_ <: Symbol])(implicit mkl: MkFieldLens[A, fieldKey.T]) = {
lens[A] >> fieldKey
fieldKey.value.name
}
println(fieldName[MyClass]('field1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment