DigitecGalaxus / Galaxus.Functional

A package bringing popular functional abstractions (e.g. Option or Result) to C#.
Other
37 stars 12 forks source link

Add Result.FlatMap #40

Closed nightruby-isa closed 1 year ago

nightruby-isa commented 1 year ago

Would love to have FlatMap option on Result.

Mapping with same error type packing them together.

In bigger Pipelines where the Result on a Map returns a Result itself makes it hard to chain together, especially if you are in an async context.

Result<Foo, Error> CreateFoo(Bar b);
Result<Bar, Error> CreateBar();

CreateBar().Map(b => CreateFoo(b)) // creates Result<Result<Foo, Error>, Error>

CreateBar().FlatMap(b => CreateFoo(b)) // Result<Foo, Error>
nightruby-isa commented 1 year ago

AndThen has the behaviour of a FlatMap