-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Transformer from > 1 case classes to another #208
Labels
Comments
it would be cool if the patching could be combined with transformation somehow, like: |
One approach that seems to work is to just pack the source types into a tuple and build a transformer for the tuple: import io.scalaland.chimney.Transformer
import io.scalaland.chimney.dsl._
final case class Foo(a: String, b: String)
final case class Bar(c: String)
final case class FooBar(a: String, b: String, c: String)
implicit val fooAndBarToFooBar: Transformer[(Foo, Bar), FooBar] = {
case (foo, bar) =>
foo
.into[FooBar]
.withFieldConst(_.c, bar.c)
.transform
}
val f = Foo("a", "b")
val b = Bar("c")
val fb = (f, b).transformInto[FooBar]
println(fb) |
It's a duplicate of #115, so all suggestions and ideas ca be posted there. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - first, I've gotten a lot of value from this project. Your work is much appreciated.
My question: is it possible to have a Transformer that combines 2 (or more) case classes into a third case class? I've found this would be particularly useful when working with case classes representing normalized database rows. I often have a FooRow and a BarRow which I want to combine into a BazDto.
The text was updated successfully, but these errors were encountered: