8000 [Issue #32] Merge case classes by arainko · Pull Request #35 · arainko/ducktape · GitHub
[go: up one dir, main page]

Skip to content

[Issue #32] Merge case classes - #35

Merged
arainko merged 5 commits into
masterfrom
issue#32-merge-case-classes
Feb 10, 2023
Merged

arainko merged 5 commits into
masterfrom
issue#32-merge-case-classes

Conversation

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

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