Monocle icon indicating copy to clipboard operation
Monocle copied to clipboard

Lens macro-generated for a specific field should allow introspecting the name

Open nafg opened this issue 2 years ago • 2 comments

For instance, given

case class Person(age: Int)

val personAge = GenLens[Person](_.age)

It would be useful to be able to do personAge.name and get back "age". There are a number of use cases for this.

nafg avatar Jun 09 '23 05:06 nafg

Hmm. I understand why you want this, and I think it would be a nifty feature, but I feel that we'd only be able to add it onto the final class generated by GenLens and not on the Lens trait overall. Would that still be useful?

yilinwei avatar Jun 28 '23 15:06 yilinwei

Yes that's exactly what I had in mind, sorry for not being more clear. Of course it's not in the contract of lenses in general, but in the specific case of generating with the macro for a field, it would be useful as a bonus.

nafg avatar Jun 28 '23 22:06 nafg