-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Comments
I'm interested in implementing this. One question I have is should this be a different name than @altmann what are your thoughts? Below is my proposal. Happy to submit a PR for this and will update docs. var result1 = new string[] { "A", "B", "C" };
var result2 = new string[] { "D", "E", "F" };
var result3 = new string[] { "G", "H", "I" };
// Have to specify result type so compiler knows this is the IEnumerable version
var result = Result.Merge<string>(result1, result2, result3);
Console.WriteLine(String.Join(",", result.Value));
var result4 = Result.Ok("J");
var result5 = Result.Ok("K");
var result6 = Result.Ok("L");
// Do not have to specify result type
var result7 = Result.Merge(result4, result5, result6);
Console.WriteLine(String.Join(",", result7.Value)); |
@Kysluss Thank you for your preparation. I think I would call the new method with a new name. Maybe MergeFlat() or only Flat(). What do you think? If I see it correctly the first three variables (result1, result2 and result3) are not real reasults, only array of strings. I think you mean Result.Ok(new string[] { ... }); |
Thanks @altmann You are right, I was taking advantage of the implicit conversion for ease of creating a demo. I think MergeFlat might a good name because it helps explicitly state the intention of the method. I'll work on this and should have a PR either today or tomorrow for you. |
Okay, so slight complication on this one. I'm running into the error we discussed in #201 where you can't convert between things based on interface type. It might be a little bit before I have that PR ready, but will keep working on it. |
@altmann I have added #215 with a var result1 = Result.Ok(new string[] { "A", "B" });
var result2 = Result.Ok(new string[] { "C", "D" });
var result3 = Result.Ok(new string[] { "E", "F" });
// Will contain ["A", "B", "C", "D", "E", "F"]
var mergedResult = Result.MergeFlat<string, string[]>(result1, result2, result3); |
I have a requirement to merge multiple results of type
Result<IEnumerable<T>>
. Here is an example of what Im trying to do:With the above code,
Result.Merge
is returningResult<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 fromResult.Merge
.Is this the recommended way or have I missed a method signature somewhere?
The text was updated successfully, but these errors were encountered: