xavierjohn / FunctionalDDD

Functional programming with Domain Driven Design.
https://xavierjohn.github.io/FunctionalDDD/
MIT License
31 stars 1 forks source link

Compensate with Error parameter passed to the callback function #172

Closed xavierjohn closed 4 months ago

xavierjohn commented 5 months ago

Additional Compensate function that passes the Error object to the callback function.

A sample use case is to check for an item in a cache, call compensate, if the error was not found, then call a persistent storage.

Customer.FetchFromCache(customerId)
.Compensate( e => {
   if (e is NotFoundError) return Customer.FetchFromStorage(customerId);
   return Result.Failure<Customer>(e);
}