Comments (1)
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)
- Creating a custom Either type with a custom fixed Left type. HOT 1
- Conflict between LangugeExt Extension methods and LINQ Extension methods HOT 2
- AffRxExtensions.Consume blocks the waiting thread on IObservable's completion
- How to make LanguageExt.CodeGen work on Unity? HOT 2
- Seq<EitherAsync<A, B>>.SequenceParallel does not preserve order HOT 14
- FileIO bug for Test when opening new file for writing
- Directory IO bug for Test when enumerating files
- Simple Kickstart Project available? CodeGen tool is outdated? dotnet8 HOT 1
- Implicit conversion of int? to Option<int> HOT 2
- SequenceParallel performance degradation in 4.4.8 HOT 1
- Refit.ApiException: 'An error occured deserializing the response.'
- Constructor not found for LanguageExt.LongRange HOT 1
- Alternative to inherit from Fin and other monads
- EitherAsync is missing HOT 4
- Add `DoAsync` to Either types (and maybe others) HOT 2
- Release build fails for a big application HOT 5
- v5 resource tracking issue? HOT 6
- Latest v5 alpha IEnumerable<T> ToSeq() extension is missing HOT 4
- v5 await more than a single forked IO, similar to Task.WhenAll HOT 2
- Higher-Kinded Types in Algebraic Free Monads with language-ext?
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 language-ext.