-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Optional non-empty fields in patched class overwritten by empty optional fields of patcher #69
Comments
Considering current implementation, this is expected behavior. If the types of corresponding fields are the same, value from the patch is taken. However there is some support for the optional fields in the patch. Considering you have a field of type It can be demonstrated with slight modification of your example: case class User2(name: String, age: Int)
> val user2 = User2("John", 30)
user2: User2 = User2("John", 30)
> user2.patchWith(UserPatch(None, None)) == user2
res: Boolean = true Or even other way around, wrapping patch fields in Option: case class UserPatch2(name: Option[Option[String]], age: Option[Option[Int]])
> user.patchWith(UserPatch2(None, None)) == user
res: Boolean = true |
Do you think it would make sense to extend that support to the case I demonstrated ? Namely, you have a field of type |
Well, both semantics may have perfect sense in different contexts. I think it makes sense to support also your use case under a flag. Would you like to craft a PR? |
Thanks, I'll take a look once I have some time. |
I just ran into this one, and thought I could get away with defining a local @ import $ivy.{`io.scalaland::chimney:0.3.0`}
import $ivy.$
@ import io.scalaland.chimney.dsl._
import io.scalaland.chimney.dsl._
@ import io.scalaland.chimney._
import io.scalaland.chimney._
@ implicit def optionFallbackPatcher[A] = new Patcher[Option[A], Option[A]] {
def patch(o: Option[A], patch: Option[A]): Option[A] = o.orElse(patch)
}
defined function optionFallbackPatcher
@ final case class Data(o: Option[Int])
defined class Data
@ Data(Some(1)).patchWith(Data(None)) // would have expected res5 = Data(Some(1))
res5: Data = Data(None) |
Discussion on the same topic continued in #123. |
Resolved in #131. |
Consider the following:
I would expect that, if the optional fields of the patchers are empty and those of the patched class are not, the latter ones should remain. Is the current behaviour the expected one ?
The text was updated successfully, but these errors were encountered: