Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Results.Merge() where TValue is a collection #182

Open
forrestab opened this issue Apr 19, 2023 · 0 comments
Open

[Question] Results.Merge() where TValue is a collection #182

forrestab opened this issue Apr 19, 2023 · 0 comments

Comments

@forrestab
Copy link

I have a requirement to merge multiple results of type Result<IEnumerable<T>>. Here is an example of what Im trying to do:

Result<IEnumerable<SomeDto>> result = Result.Ok(Enumerable.Empty<SomeDto>());

if (someCondition)
{
    Result<IEnumerable<SomeDto>> dbResult = await CallSomeDbFunc();
    result = Result.Merge(result, dbResult);
}

if (result.IsSuccess && someCondition)
{
    // run another db function and merge with `result`
}

With the above code, Result.Merge is returning Result<IEnumerable<IEnumerable<SomeDto>>>>. What I would rather it return is the input's result type.

In order to achieve what I want, Im using ToResult to "unwrap" the return from Result.Merge.

Result.Merge(result, dbResult).ToResult(result => result.SelectMany(value => value));

Is this the recommended way or have I missed a method signature somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant