one
one copied to clipboard
Simplify `track` implementations with `Compoundable`
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.
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.