Monocle
Monocle copied to clipboard
[Focus] zoom into a common field of an enumeration
sealed trait User {
def id: Long
}
case class Reader(id: Long, isPremium: Boolean) extends User
case class Editor(id: Long, favoriteFont: String) extends User
Focus[User](_.id)
// res: Lens[User, Long]
Original issue: https://github.com/optics-dev/Monocly/issues/14
Do we require a common method in the supertrait, or do we just scout around for fields with the same name & type in the case classes?
Without common method, I don't think we can get code completion from IDE. At least, I don't see another way.
One of the earlier versions of the ticket had selection over different case classes without a supertrait method, but the usecase doesn't make any sense to me. I don't see why anyone would want that, so I strongly agree there should be a supertrait method
I wonder if it's possible to change the implementation of .focus
, so doesn't directly invoke the macro but instead takes an implicit parameter for a lens (with the macro one given as default), so in the application code there's a way to at least manually provide the instances. Will it increase compile time because of all the implicit searches though?