ardalis / ardalis/Result

How to convert Result<Foo> to Result<RandomClass> when result is not success

Open
#219 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1k
Forks
127
PR merge metrics
No merged PRs in 30d

Description

Question:

I may call in a method different services. When result is success I use result.Value to continue but if there are errors like conflict or anything else I want to return and stop execution there but I want to keep errors. Map is not always possible (I guess). Is there a good way to accomplish this? Should I use map with an empty value like return result.Map(new RandomClass()) only to keep errors since value wont matter at this point. Or can I just return result.Map();?

```
public Result ReturnIntResult(int id)
{
Result resultFromService = _service.GetFoo(id)

if(!result.IsSucces)
{
//How can I return a type Result with errors from resultFromService? Like conflict or anything else. I have seen some basic example with int and string using Map. But sometime _service can return value and errors which value is used later but mapping is not necessary needed for the value. Only for the error;
return ???;
}

return new Result(resultFromService.Value);
}
```

Contributor guide

Open the contributing guide

Research direction

The issue provides no repository file or test entry point. Start by reviewing the Result and Map usage shown in the question, then inspect the library’s existing APIs for converting results while preserving errors. Done means reaching a maintainer-approved decision about the supported behavior and documenting or implementing it as appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.