Skip to content

Fix #772 ComputedPartialFailFast - #875

Merged
MateuszKubuszok merged 3 commits into
masterfrom
issue-772-computed-partial-fail-fast
Apr 25, 2026
Merged

MateuszKubuszok merged 3 commits into
masterfrom
issue-772-computed-partial-fail-fast

Conversation

@MateuszKubuszok

@MateuszKubuszok MateuszKubuszok commented Apr 25, 2026

Copy link
Copy Markdown
Member

Summary

Closes #772.

Adds fail-fast-aware variants of partial transformer DSL methods. These accept functions that receive a failFast: Boolean parameter, allowing users to optimize partial computations based on whether .transform (collects all errors, failFast = false) or .transformFailFast (stops at first error, failFast = true) was used.

New methods

Added to both PartialTransformerInto and PartialTransformerDefinition (Scala 2.12, 2.13, and 3):

Method Function signature
withFieldComputedPartialFailFast (From, Boolean) => partial.Result[U]
withFieldComputedPartialFromFailFast (S, Boolean) => partial.Result[U]
withSealedSubtypeHandledPartialFailFast (Subtype, Boolean) => partial.Result[To]
withEnumCaseHandledPartialFailFast alias for the above
withConstructorPartialFailFast curried: (a, b, ...) => (failFast: Boolean) => partial.Result[To]
withConstructorPartialToFailFast curried, with target selector

Example

Foo("value", 10)
  .intoPartial[Bar]
  .withFieldComputedPartialFailFast(_.c, (foo, failFast) =>
    if (failFast) partial.Result.fromValue(foo.b.toLong)      // skip expensive work
    else partial.Result.fromValue(foo.b.toLong * 2)           // full computation
  )
  .transformFailFast // failFast = true

Implementation details

  • Type-level entries: ComputedPartialFailFast, ComputedPartialFromFailFast, CaseComputedPartialFailFast, ConstructorPartialFailFast added to TransformerOverrides
  • Internal representation: failFastAware: Boolean flag on TransformerOverride.ComputedPartial and ConstructorPartial
  • Curried storage: Functions are stored curried (A => Boolean => Result[B]) since chimney-macro-commons only supports Expr.apply for Function1
  • Rule modules: TransformProductToProductRuleModule and TransformSealedHierarchyToSealedHierarchyRuleModule updated to thread ctx.failFast when failFastAware = true

Tests

  • withFieldComputedPartialFailFast passes correct failFast via transform and transformFailFast
  • withFieldComputedPartialFromFailFast variant
  • withSealedSubtypeHandledPartialFailFast for sealed hierarchies
  • PartialTransformer.define builder variant

Documentation

  • New "Fail-fast-aware partial computations" subsection in supported-transformations.md
  • Runnable Scala CLI snippet demonstrating failFast flag behavior

Add withFieldComputedPartialFailFast, withFieldComputedPartialFromFailFast,
withSealedSubtypeHandledPartialFailFast, withEnumCaseHandledPartialFailFast,
withConstructorPartialFailFast, and withConstructorPartialToFailFast methods
to PartialTransformerInto and PartialTransformerDefinition (both Scala 2 and 3).

These methods accept functions that take a `failFast: Boolean` parameter,
allowing users to optimize partial computations based on whether fail-fast
mode is active. Field/subtype functions use `(From, Boolean) => Result[U]`,
constructor functions use curried `(a, b) => (failFast) => Result[To]`.

Internally, functions are stored curried (`A => Boolean => Result[B]`) to
work with chimney-macro-commons' Function1-only Expr.apply support.
Add "Fail-fast-aware partial computations" subsection to
supported-transformations.md with a runnable Scala CLI snippet
demonstrating withFieldComputedPartialFailFast behavior with
transform vs transformFailFast.

All doc snippets pass.
@codecov

codecov Bot commented Apr 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.04651% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.04%. Comparing base (f71b758) to head (3dfe210).
⚠️ Report is 103 commits behind head on master.

Files with missing lines Patch % Lines
...er/rules/TransformProductToProductRuleModule.scala 38.23% 21 Missing ⚠️
...ey/internal/compiletime/ChimneyTypesPlatform.scala 56.25% 14 Missing ⚠️
...letime/derivation/transformer/Configurations.scala 63.88% 13 Missing ⚠️
...ey/internal/compiletime/ChimneyTypesPlatform.scala 76.31% 9 Missing ⚠️
...etime/dsl/PartialTransformerDefinitionMacros.scala 20.00% 8 Missing ⚠️
...compiletime/dsl/PartialTransformerIntoMacros.scala 60.00% 4 Missing ⚠️
...rmSealedHierarchyToSealedHierarchyRuleModule.scala 84.61% 2 Missing ⚠️
...etime/dsl/PartialTransformerDefinitionMacros.scala 90.00% 1 Missing ⚠️
...compiletime/dsl/PartialTransformerIntoMacros.scala 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #875      +/-   ##
==========================================
- Coverage   86.08%   85.04%   -1.05%     
==========================================
  Files         154      154              
  Lines        6923     7116     +193     
  Branches      779      794      +15     
==========================================
+ Hits         5960     6052      +92     
- Misses        963     1064     +101     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MateuszKubuszok
MateuszKubuszok force-pushed the issue-772-computed-partial-fail-fast branch from 59d73e3 to 3dfe210 Compare April 25, 2026 05:53
@MateuszKubuszok MateuszKubuszok changed the title Issue 772 computed partial fail fast ComputedPartialFailFast Apr 25, 2026
@MateuszKubuszok
MateuszKubuszok merged commit 7b27f6d into master Apr 25, 2026
22 of 24 checks passed
@MateuszKubuszok
MateuszKubuszok deleted the issue-772-computed-partial-fail-fast branch April 25, 2026 06:28
@MateuszKubuszok MateuszKubuszok changed the title ComputedPartialFailFast Fix #772 ComputedPartialFailFast Apr 26, 2026
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.

Create withFieldComputedPartial version that takes (from: From, failFast: Boolean) => ...

1 participant