arainko / ducktape

Automatic and customizable compile time transformations between similar case classes and sealed traits/enums, essentially a thing that glues your code. Scala 3 only. Or is it duct 🤔

Home Page:https://arainko.github.io/ducktape/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for non-singleton enums cases and sealed trait children

susliko opened this issue · comments

The following example fails to compile, for transformers are only derived for singleton enum cases and case object children of sealed traits

//> using scala "3.3.0-RC4"
//> using lib "io.github.arainko::ducktape:0.1.7"
import io.github.arainko.ducktape.*

sealed trait X
object X:
  case object A extends X
  case class B(b: String) extends X

sealed trait Y
object Y:
  object A extends Y
  case class B(b: String) extends Y

enum XE:
  case A
  case B(a: String)
enum YE:
  case A
  case B(a: String)

@main def main =
  implicitly[Transformer[X, Y]] // Cannot materialize singleton for B
  implicitly[Transformer[XE, YE]] // Cannot materialize singleton for B

Are there any technical limitations or design considerations that make support of these cases impossible or undesirable?

Thanks for the suggestion! I'm glad to say I'm one step ahead on that and started tinkering on this in this branch some days ago: https://github.com/arainko/ducktape/tree/more-advanced-coproduct-transformations, havent't had time to properly test/document it yet tho - but stay tuned, it is on its way :)