How do you force the evaluation of an IEnumerable<EitherAsync<Error, Unit>>?
For context, lets assume:
var l = new List<string>().AsEnumerable()
.Map(s => HttpPost(s)); // HttpPost returns EitherAsync<Error, Unit>
Task.WhenAll(l); // Compiler Error
Task.WhenAll() can take IEnumerable<Task> but not IEnumerable<EitherAsync<>>.
I was hoping to be able to access the task in the EitherAsync:
IEnumerable<EitherAsync<Error, Unit>>
.Map(ea => {
var e = await ea; // But can't await because its not a task
return e.AsTask();
})
// OR
.Map(ea => {
return ea.GetAsATask(); // But I can't find a method like this.
})
This seems to do it - but its pretty boiler plate. Thoughts?
IEnumerable<EitherAsync<Error, Unit>>
.Map(ea =>
ea.MatchAsync(
LeftAsync: e => Left(e).AsTask(),
RightAsync: u => Right(u).AsTask()
)
)
As a broader question - I've been finding that I'm using EitherAsync as a return type all over and I haven't found anything in LangExt to help trigger the evaluation. Are there any helper functions that help when evaluating larger sets of tasks that may do a bunch of IO?
I think this will work.
var l = new List<string>().AsEnumerable()
.Map(s => HttpPost(s).ToEither());
Task.WhenAll(l);
Oh nice, that did the trick. Thanks
.ToEither() - Converted from EitherAsync<> to Task<Either<>>
Most helpful comment
I think this will work.