CSharpFunctionalExtensions
CSharpFunctionalExtensions copied to clipboard
With Extensions (Combine)
These extensions will allow you combine Results. This is done by combining successful values using a factory + merging errors using a factory
Example
var r1 = Result.Success(1);
var r2 = Result.Success(3);
var combined = r1.With(r2, (x, y) => x + y);
combined will contain a success with a value of 4
I removed the tests because I still have to think about a good way to test every overload without making a mess.
Personally I feel it's better to use SelectMany via the fluent syntax (which I hate and it's the single case where I'm ok to use it) for such complex cases.
And, speaking honestly, I think those extensions do too much. It's hard to understand all those positional and generic parameters.
Example from tests:
await r1.WithMap(r2, (a, b) => Task.FromResult(a + b), (e1, e2) => "failure"); // I don't feel it's simple and easy to read/understand