CSharpFunctionalExtensions icon indicating copy to clipboard operation
CSharpFunctionalExtensions copied to clipboard

With Extensions (Combine)

Open SuperJMN opened this issue 4 years ago • 2 comments

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

SuperJMN avatar Oct 11 '21 09:10 SuperJMN

I removed the tests because I still have to think about a good way to test every overload without making a mess.

SuperJMN avatar Oct 11 '21 09:10 SuperJMN

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

hankovich avatar Nov 08 '21 11:11 hankovich