-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The current handling of data results are incredibly complex, and the code that handles the result objects are responsible for the majority of the cognitive complexity of a method (not to mention the amount of time needed to type them in), as shown below:
var resultA = MethodA().RequireNonEmpty();
if (resultA.Error != null)
{
return DataResult<ObjectA>.CausedBy(resultA);
}
return MethodB(resultA.Result!);This issue proposes new data result handling APIs that have two level distinctions:
Level 1
- Implicitly converts
OpResultto a failure or emptyDataResult - Add an
!operator that returnstrueif the result is not successful - Add a
Foldmethod to convertDataResulttoOpResult - Introduce
Resultsclass which support implicit type arguments for data results better
This turns the above code down to:
var resultA = MethodA().RequireNonEmpty();
if (!resultA)
{
return resultA.Fold();
}
return MethodB(resultA.Result!);While this do not do much for cognitive complexity, it is way easier to type.
Level 2
Making APIs accept DataResult directly will mean that a failure result can be passed down and the same result will be returned. So this would become:
return MethodB(MethodA());Significantly better because method chaining is now possible.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request