Giter Club home page Giter Club logo

Comments (1)

louthy avatar louthy commented on June 10, 2024

You could try this approach instead: using Lefts which will get all the errors from a collection...

public EitherAsync<Error, Unit> MainFunction(Command cmd) =>
    // Early out is good
    from data1 in GetData1(cmd)
    from data2 in GetData2(cmd)
    from data3 in GetData3(cmd)
    from data4 in GetData4(cmd)
    
    // No early out anymore
    let process1 = ProcessData1(data1)
    let process2 = ProcessData2(data2)
    let process3 = ProcessData3(data3)
    let process4 = ProcessData4(data4)

    // Collect the lefts from the processes.  If there aren't any
    // then return Right, else collect the Errors together and return
    // Left
    from result in Seq(process1, process2, process3, process4)
                       .Lefts()
                       .Map(errors => errors.IsEmpty
                           ? Right<Error, Unit>(unit)
                           : Left<Error, Unit>(Error.Many(errors)))
                       .ToAsync()

    select result;

NOTE: This is using the Error type from language-ext, which allows for the collection of multiple errors.

Really you're trying to do the work of a validation monad rather than an either here. You might want to consider developing a more bespoke monad for your use-case, or use language-ext's Validation monad - it is synchronous though, so you'd need to do your IO work before running the validation process.

from language-ext.

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.