Skip to content

[Issue 199] Add Field.computedDeep and Field.fallibleComputedDeep#220

Merged
arainko merged 14 commits intoseries/0.2.xfrom
issue-199-computed-deep
Oct 30, 2024
Merged

[Issue 199] Add Field.computedDeep and Field.fallibleComputedDeep#220
arainko merged 14 commits intoseries/0.2.xfrom
issue-199-computed-deep

Conversation

@arainko
Copy link
Copy Markdown
Owner

@arainko arainko commented Oct 30, 2024

Closes #199

This adds two new config options that allow to computing deeply nested fields (with the value that corresponds to the source value under the config path).
Example:

 case class SourceToplevel1(level1: Option[SourceLevel1])
    case class SourceLevel1(level2: Option[SourceLevel2])
    case class SourceLevel2(level3: SourceLevel3)
    case class SourceLevel3(int: Int)

    case class DestToplevel1(level1: Option[DestLevel1])
    case class DestLevel1(level2: Option[DestLevel2])
    case class DestLevel2(level3: Option[DestLevel3])
    case class DestLevel3(int: Long)

    val source = SourceToplevel1(Some(SourceLevel1(Some(SourceLevel2(SourceLevel3(1))))))
    val expected = DestToplevel1(Some(DestLevel1(Some(DestLevel2(Some(DestLevel3(11)))))))

    assertTransformsConfigured(source, expected)(
      Field.computedDeep(_.level1.element.level2.element.level3.element.int, (int: Int) => int.toLong + 10)
    )

@arainko arainko force-pushed the issue-199-computed-deep branch from 122b477 to d2105f7 Compare October 30, 2024 20:28
@arainko arainko force-pushed the issue-199-computed-deep branch from d2105f7 to f2d3e10 Compare October 30, 2024 20:32
@arainko arainko merged commit ccdeb45 into series/0.2.x Oct 30, 2024
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.

Add a way of using a Field.computed-like construct to compute deeply nested properties

1 participant