Skip to content

Instantly share code, notes, and snippets.

@andyczerwonka
Last active December 15, 2020 19:43
Show Gist options
  • Save andyczerwonka/4486bae9e7160419d7a0bc91573baf0b to your computer and use it in GitHub Desktop.
Save andyczerwonka/4486bae9e7160419d7a0bc91573baf0b to your computer and use it in GitHub Desktop.
Chimney Coproduct Case
import io.scalaland.chimney.dsl._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
class TransformationTest extends AnyFunSuite with Matchers {
sealed trait A extends Product with Serializable
object A {
case class Foo(s: String) extends A
case class Bar(kvs: Map[String, Int]) extends A
}
sealed trait B extends Product with Serializable // same structure as A
object B {
case class Foo(s: String) extends B
case class Bar(kvs: Map[String, Int]) extends B
}
sealed trait C extends Product with Serializable
object C {
case class Foo(s: String) extends C
case class Bar(keys: Seq[String], values: Seq[Int]) extends C
}
case class Bag[T](xs: Seq[T])
test("transforming a coproduct with identical structure") {
val as = Seq(A.Foo("foo"), A.Bar(Map("bar" -> 1)))
val transformed = as.transformInto[Seq[B]]
succeed
}
}
@andyczerwonka
Copy link
Author

Internal error: unable to find the outer accessor symbol of class TransformationTest
[error]     val transformed = as.transformInto[Seq[B]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment