magnolia
magnolia copied to clipboard
consider merging `ReadOnly...` APIs
The read-only APIs give us faster compilation by introducing new supertraits for the CaseClass and SealedTrait interfaces which save the cost of generating methods we are not going to use. We don't have "write-only" interfaces, but a similar approach could be used, at the expense of more complexity in the lifted interface hierarchy.
However, if Magnolia knew that one of these approaches was required, it could use the same interface, but simply implement the unused methods with ???.
There is a question about how it would determine this, but I would suggest checking whether final val readOnly = true or final val writeOnly = true exist in the derivation object; each should be typed as true.type, hence the use of final. (They could also be typed as Unit and their mere existence would be the application of that flag.)
Interesting idea! How about a sealed trait of ReadOnly/WriteOnly/ReadWrite? With them being case objects it'll work too right? I can take a stab at this if you want?
That sounds better. But I'm still not sure how the API should look like. My only worry is that making it name-based could be too obscure.
Something like this?
object ShowDerivation {
val typeclassAccess = TypeclassAccess.ReadOnly
type Typeclass[T] = Show[T]
def combine[T](ctx: CaseClass[Show, T]): Show[T] = ...
// etc
}