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 🤔
enum SourceLevel3 {
case One(int: Int)
case Two(str: String)
}
enum DestLevel3 {
case One(int: Long)
case Two(str: String)
}
val source = SourceLevel3.One(1)
val expected = DestLevel3.One(6)
source.into[DestLevel3].transform(
Field.const(_.at[DestLevel3.One], DestLevel3.One(2L))
)
result:
sbt:root> ducktapeJVM/run
[info] running io.github.arainko.ducktape.test
Exception in thread "sbt-bg-threads-7" java.lang.ExceptionInInitializerError
at io.github.arainko.ducktape.test.main(Mode.scala)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at sbt.Run.invokeMain(Run.scala:144)
at sbt.Run.execute$1(Run.scala:94)
at sbt.Run.$anonfun$runWithLoader$5(Run.scala:121)
at sbt.Run$.executeSuccess(Run.scala:187)
at sbt.Run.runWithLoader(Run.scala:121)
at sbt.Defaults$.$anonfun$bgRunTask$6(Defaults.scala:2038)
at sbt.Defaults$.$anonfun$termWrapper$2(Defaults.scala:1977)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at scala.util.Try$.apply(Try.scala:213)
at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:367)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.RuntimeException: Unhandled case. This is most likely a bug in ducktape.
at io.github.arainko.ducktape.test$.<clinit>(Mode.scala:191)
... 16 more
[success] Total time: 0 s, completed Oct 13, 2024, 12:59:01 PM
sbt:root>
result:
It works if we configure the innermost fields.
Yikes.