one icon indicating copy to clipboard operation
one copied to clipboard

Simplify `track` implementations with `Compoundable`

Open propensive opened this issue 8 months ago • 1 comments

Currently, in a track block, we must specify an initial "empty" error and specify how the error should be modified to include a new validation error, using accrual to refer to the previous error.

Instead, let's use typeclasses to define how new validation errors can be appended to an existing error.

trait Compoundable:
  type Self <: Exception
  type Operand
  def compound(error: Self, issue: Operand): Self

We can use a Zeroic instance for the initial value.

propensive avatar May 10 '25 10:05 propensive

This might not be the best way. A better way might be to support something like this:

validate:
    case FooError(...) => m"unfortunately foo"
    case BarError(...) => m"sadly, bar"
    case BazError(...) => m"baz tragedy"
. combine:
    (issues: List[Message]) => AggregateError(issues)
. within:
    doSomething()

which has a separate "combine" step for aggregating several instances of a particular type into a single error.

propensive avatar Nov 05 '25 08:11 propensive