8000 [Issue #32] Merge case classes by arainko · Pull Request #35 · arainko/ducktape · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Issue #32] Merge case classes #35

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

Merged
merged 5 commits into from
Feb 10, 2023
Merged

Conversation

arainko
Copy link
Owner
@arainko arainko commented Feb 10, 2023

Closes #32

Adds a new configuration option for case class to case class transformations (can also be implemented for Arg), Field.allMatching, example usage looks like this:

import io.github.arainko.ducktape.*

final case class Person(firstName: String, lastName: String, age: Int)
final case class PersonButMoreFields(firstName: String, lastName: String, age: Int, socialSecurityNo: String)
val person = Person("Jerry", "Smith", 20)

final case class FieldSource(lastName: String, socialSecurityNo: String)
// 4. Grab and use all matching fields from a different case class (a compiletime error will be issued if none of the fields match)
val withAllMatchingFields = 
  person
    .into[PersonButMoreFields]
    .transform(Field.allMatching(FieldSource("SourcedLastName", "SOURCED-SSN")))
// withAllMatchingFields: PersonButMoreFields = PersonButMoreFields(
//   firstName = "Jerry",
//   lastName = "SourcedLastName",
//   age = 20,
//   socialSecurityNo = "SOURCED-SSN"
// )

It'll also issue a compiletime failure in case none of the fields of the case class you pass in match the any of the fields from the source case class

@arainko arainko merged commit d5ddb67 into master Feb 10, 2023
@arainko arainko deleted the issue#32-merge-case-classes branch February 12, 2023 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow merging case classes
1 participant
0