Comments (5)
In the library, Map is basically just for transforming a Result<T>
into a Result<K>
, this is not a fully-fledged Map from functional languages. Right now, there are only versions of this operation in OnSuccess and OnFailure methods. I guess what you are looking for is an overload for the OnBoth method so that the 3rd line in your sample would execute despite the previous outcome?
from csharpfunctionalextensions.
Indeed this would not be a canonical Flatmap either, but in this case we would want a FlatMap to expect a Result<Result<T>>
and just give us the object of type T
in the lambda if the inner Result was a success. I think the harder part would be that we would want an inner Fail to be handled the same as if it were a top level fail as well.
If that doesn't make sense I can write up a proper example.
Edit: apparently markdown hid the T in Result<Result<T>>
from csharpfunctionalextensions.
While this worked easily several times, in other cases it's throwing an exception that "There is no value for failure".
from csharpfunctionalextensions.
Since result.Value only works if there are no errors, I'm now using this instead:
.OnSuccess(result => result.Value)
.OnFailure(error => Result.Fail(error));
Obviously this is sub-optimal for a few reasons. Not only is it unsightly, I also think I'm losing the type in the Fail condition. This might not be an issue though, I'm not sure.
Eventually I'll probably try to create FlatMap and submit a PR, if you could just let me know if you'd be willing to entertain such a PR.
from csharpfunctionalextensions.
It turns out that the solution was just to use OnSuccess instead of Map.
Map should only be used if the function following it returns a value which does is not of type "Result"
from csharpfunctionalextensions.
Related Issues (20)
- Making ValueObject.GetEqualityComponents return IComparable is a breaking change HOT 9
- Ensure returns Success instead of Failure HOT 4
- Any plans to add more advanced concepts? HOT 5
- Proposal for a TapIf overload HOT 1
- Question: Result<T,E> with interfaces HOT 1
- EF Core 7: The LINQ expression 'DbSet could not be translated when using Value Object HOT 2
- More examples HOT 1
- Question: return the result HOT 1
- Accept an errorFactory when converting Maybe to Result HOT 1
- Bind chain with different return type HOT 2
- Suggestion: split ValueObject to seperate nuget in order to safely trimming HOT 1
- Proposal: AsMaybeAsync HOT 1
- Serialization HOT 2
- Moving extension methods onto `IResult` (to enable covariance) HOT 1
- Proposal: An Error class which has an inner error. HOT 5
- [Proposal] BindZip to store both income and outcome of Bind HOT 3
- [Question] Adding shared context for Result which presents in both Success and Error cases HOT 1
- Add IError<string> to the Result struct HOT 4
- [Question] How to handle different Error types in railway chain HOT 6
- [Suggestion] `Result.Of()` to start a chain with a value HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csharpfunctionalextensions.