Using Either and Bind when the outputs of two separate functions feeds into the next function #1210
-
Hi there, Is there an approach I should use when using Either and Bind, when the outputs of two separate functions feed into the next function? I could just refactor the whole thing in various ways to get around the problem, but I'm guessing there's a cleaner and less contrived way? In the example below my DoMapping function needs both a Something and an Input, therefore I can't chain them altogether with Bind. Hope that makes sense? Either<Error, Input> ValidateInput(Input input) => input;
Either<Error, Something> GetSomething() => new Something();
Either<Error, MappedInput> DoMapping(Input input, Something something) => new MappedInput();
Either<Error, Response> CallSomethingExternal(MappedInput input) => new Response(); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think I've just discovered that if I use the Linq query syntax for select many then you can achieve this very easily? Still curious to know how best to do this using Bind method chaining though. e.g var result =
await (
from a in GetInputs()
from b in UserConfirm(a).ToAsync()
from c in Validate(b).ToAsync()
from d in GetSomething().ToAsync()
from e in DoMapping(c, d).ToAsync()
select e
); |
Beta Was this translation helpful? Give feedback.
I think I've just discovered that if I use the Linq query syntax for select many then you can achieve this very easily? Still curious to know how best to do this using Bind method chaining though.
e.g