You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I did is, I added extensions methods for IResult<TValue> and also for IResultBase for the following methods:
MapErrors
MapSuccesses
Bind
Map
ToResult<TValue>
I copied those methods from the Result class and the Result<TValue> class.
I designed those methods, to return either IResult<TValue> (Task<IResult<TValue>>, ValueTask<IResult<TValue>> resp.) or IResultBase (Task<IResultBase>, ValueTask<IResultBase> resp.).
Whenever a new result is created, the IResult<TValue> is actually a Result<TValue>.
This has the disadvantage, that, if the input result had covariance, the output result loses this covariance. This could be circumvented with Reflection, but I am not sure, if this is a good idea.
Alternatives:
Instead of directly providing extension methods for Map, Bind, etc., we could just provide an extensionsMethod AsResult() like that:
Then you could convert an IResult to a result, before working with it.
This method assumes, that most IResults are actually already Results. That is of course not the case, if the result is covariant. In that case, we create a new result object. I named the method AsResult, because in most cases it doesn't create a new object. But that is of course not true, the better name would be ToResult, but that name is of cource already taken for another functionality.
The advantage is, we have fewer methods to maintain. The disadvantage is, that in the case of actual covariance we have create a new object, while an actual extensions method for MapErrorss for instance, could just return the input object instead.
So what do you think?
The text was updated successfully, but these errors were encountered:
I tried to change my code from
Result<TValue>
toIResult<TValue>
and realized, thatIResult<TValue>
doesn’t have aBind
or aMap
methods.I think
Bind
andMap
are very important features, therefore I propose adding those methods as Extensions methods.I prepared some code changes in a fork of this project (see here: https://github.com/DrPepperBianco/FluentResults/blob/features/extensionmethods_for_interface_types/src/FluentResults/Extensions/ResultExtensions.cs).
What I did is, I added extensions methods for
IResult<TValue>
and also forIResultBase
for the following methods:MapErrors
MapSuccesses
Bind
Map
ToResult<TValue>
I copied those methods from the
Result
class and theResult<TValue>
class.I designed those methods, to return either
IResult<TValue>
(Task<IResult<TValue>>
,ValueTask<IResult<TValue>>
resp.) orIResultBase
(Task<IResultBase>
,ValueTask<IResultBase>
resp.).Whenever a new result is created, the
IResult<TValue>
is actually aResult<TValue>
.This has the disadvantage, that, if the input result had covariance, the output result loses this covariance. This could be circumvented with Reflection, but I am not sure, if this is a good idea.
Alternatives:
Instead of directly providing extension methods for
Map
,Bind
, etc., we could just provide an extensionsMethodAsResult()
like that:Then you could convert an IResult to a result, before working with it.
This method assumes, that most
IResults
are actually alreadyResults
. That is of course not the case, if the result is covariant. In that case, we create a new result object. I named the methodAsResult
, because in most cases it doesn't create a new object. But that is of course not true, the better name would beToResult
, but that name is of cource already taken for another functionality.The advantage is, we have fewer methods to maintain. The disadvantage is, that in the case of actual covariance we have create a new object, while an actual extensions method for
MapErrorss
for instance, could just return the input object instead.So what do you think?
The text was updated successfully, but these errors were encountered: