-
Presently I am using Functional Extension in following way Result<EntityA> a= await ResolveEntityAFromDb(request.AId, token);
if (a.IsFailure) return a.Error;
Result<EntityB> b = await ResolveEntityBFromDb(request.BId, token);
if (b.IsFailure) return b.Error;
EntityC c = Map(a.Result, b.Result, request);
await dbContext.SaveChanges();
return Result.Success; I want to avoid having if(a.IsFailure), if (b.IsFailure) checks and make it railway oriented. Any Ideas of how I can chain such operations and use results of all previous operations (ResolveEntityAFromDb, ResolveEntityBFromDb) in last step. |
Beta Was this translation helpful? Give feedback.
Answered by
hankovich
Mar 28, 2024
Replies: 2 comments 4 replies
-
Hi, you can use something like return ResolveEntityAFromDb(request.AId, token)
.Bind(result1 => ResolveEntityBFromDb(request.BId, token).Map(result2 => (result1, result2))
.Map(tuple => Map(tuple.result1, tuple.result2, request))
.Tap(() => dbContext.SaveChanges()); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
raanam
-
Yeah, we can add the additional extension for sure. I usually use a workaround like this: Result result1 = ResolveEntityAFromDb(request.AId, token);
result1.Bind(_ => ResolveEntityBFromDb(request.BId, token)
.Map(entityB => Map(result1.Value, entityB).
.... |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, you can use something like