-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to extend a trait from a record type's companion object ? #61
Comments
Nothing like exactly like that currently. However there's a way to customize how case classes are generated. It uses these models. Maybe there's a way to adapt that to get what you want? Maybe something like an optional field with a default of Did you have something in mind, maybe like |
The issue I have here is that, when I define a type in idl I would need also to place the typeclass instances for that type in the companion object, so what would help is a way to tell the generator how to place those instances in there. As an example consider I wanted to put the instance for trait TestInstances {
implicit final val testShow: Show[Test] = ???
} Or even create a hierarchy that would give me different priorities like trait TestInstances extends LowPriorityTestInstances {
implicit final val testShow: Show[Test] = ???
}
sealed trait LowPriorityTestInstances {
/** other low priority instances here **/
} Anything that works on the way the case class is generated or on the type I'm afraid doesn't work. protocol TestProtocol {
@companion-is-a("my.fully.qualified.namespace.TestInstances") or
@companion-extends("my.fully.qualified.namespace.TestInstances")
record Test {
long id;
string text;
}
} with the care of making |
At the moment when generating a
record
(I use a SpecificRecord but I guess is the same for the others) also the companion object of the case class is (correctly) generated. So for something likethe generated code is
Is there any way I could specify a trait that would be extended by the companion object ? Something like
The use case I have is that this way it would be possible to put type class instances in the implicit scope for the generated types avoiding orphans. Thanks.
The text was updated successfully, but these errors were encountered: