Hello, thank you for the fantastic library!
Typeclasses that modify a case class instances will need to call the copy method. Given there are quite a few edge cases to handle, perhaps Hearth can add a helper for it? Let me know your thoughts and I'll take a stab at the implementation.
Describe the desired behavior
Add a helper method on hearth.typed.Classes.CaseClass so macro code can easily obtain reference to copy
lazy val copyMethod: Option[Method.OfInstance[A, A]] = ...
Implementation:
- Only returns the "canonical"
copy method, which has a parameter list that matches the case class primary constructor parameters
- edge cases like
case class Boo(i: Int)(s: Int) need to be handled too
- If the right
copy method cannot be found (e.g. sealed abstract case class), return None
Use case example
val cc: CaseClass[A] = CaseClass.parse[A].toOption.getOrElse(..)
val copyMethod = cc.copyMethod.getOrElse(..)
val ccInstance: Expr[A] = ..
val args: Arguments = ...
copyMethod.apply(ccInstance, args)
How it relates to existing features
Currently user can use Method.methodsOf[A].find(_.value.name == "copy"), but all edge cases will need to be handled by the user
Other considerations
- Need to deal with public/private copy methods. Perhaps add a
copyMethodPublic which is the most common use case?
Hello, thank you for the fantastic library!
Typeclasses that modify a case class instances will need to call the
copymethod. Given there are quite a few edge cases to handle, perhaps Hearth can add a helper for it? Let me know your thoughts and I'll take a stab at the implementation.Describe the desired behavior
Add a helper method on
hearth.typed.Classes.CaseClassso macro code can easily obtain reference tocopyImplementation:
copymethod, which has a parameter list that matches the case class primary constructor parameterscase class Boo(i: Int)(s: Int)need to be handled toocopymethod cannot be found (e.g.sealed abstract case class), return NoneUse case example
How it relates to existing features
Currently user can use
Method.methodsOf[A].find(_.value.name == "copy"), but all edge cases will need to be handled by the userOther considerations
copyMethodPublicwhich is the most common use case?