Last active
December 15, 2020 19:43
-
-
Save andyczerwonka/4486bae9e7160419d7a0bc91573baf0b to your computer and use it in GitHub Desktop.
Chimney Coproduct Case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Author
andyczerwonka
commented
Dec 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment