Giter Site home page Giter Site logo

Comments (5)

vkhorikov avatar vkhorikov commented on September 13, 2024

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.

solvingj avatar solvingj commented on September 13, 2024

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.

solvingj avatar solvingj commented on September 13, 2024

While this worked easily several times, in other cases it's throwing an exception that "There is no value for failure".

from csharpfunctionalextensions.

solvingj avatar solvingj commented on September 13, 2024

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.

solvingj avatar solvingj commented on September 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.