Skip to content

Commit

Permalink
Fix - Reasons is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
altmann committed Jun 26, 2024
1 parent 2d34d57 commit 09aec15
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/FluentResults/Factories/ResultHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static Result<IEnumerable<TValue>> MergeWithValue<TValue>(
var resultList = results.ToList();

var finalResult = Result.Ok<IEnumerable<TValue>>(new List<TValue>())
.WithReasons(resultList.SelectMany(result => result.Reasons));
.WithReasons(resultList.SelectMany(result => result.Reasons));

if (finalResult.IsSuccess)
finalResult.WithValue(resultList.Select(r => r.Value).ToList());
Expand All @@ -40,13 +40,11 @@ public static bool HasError<TError>(
}

foreach (var error in errors)
{
if (HasError(error.Reasons, predicate, out var fErrors))
if (HasError(error.Reasons ?? new List<IError>(), predicate, out var fErrors))
{
result = fErrors;
return true;
}
}

result = Array.Empty<TError>();
return false;
Expand All @@ -59,9 +57,9 @@ public static bool HasException<TException>(
where TException : Exception
{
var foundErrors = errors.OfType<ExceptionalError>()
.Where(e => e.Exception is TException rootExceptionOfTException
&& predicate(rootExceptionOfTException))
.ToList();
.Where(e => e.Exception is TException rootExceptionOfTException
&& predicate(rootExceptionOfTException))
.ToList();

if (foundErrors.Any())
{
Expand All @@ -70,26 +68,24 @@ public static bool HasException<TException>(
}

foreach (var error in errors)
{
if (HasException(error.Reasons, predicate, out var fErrors))
if (HasException(error.Reasons ?? new List<IError>(), predicate, out var fErrors))
{
result = fErrors;
return true;
}
}

result = Array.Empty<IError>();
return false;
}

public static bool HasSuccess<TSuccess>(
List<ISuccess> successes,
List<ISuccess> successes,
Func<TSuccess, bool> predicate,
out IEnumerable<TSuccess> result) where TSuccess : ISuccess
{
var foundSuccesses = successes.OfType<TSuccess>()
.Where(predicate)
.ToList();
.Where(predicate)
.ToList();
if (foundSuccesses.Any())
{
result = foundSuccesses;
Expand Down

0 comments on commit 09aec15

Please sign in to comment.