chore: small consistency improvements
All checks were successful
default / dotnet default workflow (8.0) (push) Successful in 34s

This commit is contained in:
Louis Seubert 2024-07-12 15:49:25 +02:00 committed by Louis Seubert
parent b3ed128536
commit 75314d8f7c
3 changed files with 38 additions and 44 deletions

View file

@ -45,7 +45,7 @@ public static partial class Extensions
/// </remarks>
/// <seealso cref="Join{T}(System.Collections.Generic.IEnumerable{Geekeey.Extensions.Result.Result{T}})"/>
// ReSharper disable once InconsistentNaming
public static async Task<Result<IReadOnlyList<T>>> Join<T>(this IEnumerable<Task<Result<T>>> results)
public static async ValueTask<Result<IReadOnlyList<T>>> Join<T>(this IEnumerable<ValueTask<Result<T>>> results)
{
_ = results.TryGetNonEnumeratedCount(out var count);
var list = new List<T>(count);
@ -70,7 +70,7 @@ public static partial class Extensions
/// </remarks>
/// <seealso cref="Join{T}(System.Collections.Generic.IEnumerable{Geekeey.Extensions.Result.Result{T}})"/>
// ReSharper disable once InconsistentNaming
public static async ValueTask<Result<IReadOnlyList<T>>> Join<T>(this IEnumerable<ValueTask<Result<T>>> results)
public static async Task<Result<IReadOnlyList<T>>> Join<T>(this IEnumerable<Task<Result<T>>> results)
{
_ = results.TryGetNonEnumeratedCount(out var count);
var list = new List<T>(count);

View file

@ -12,6 +12,36 @@ namespace Geekeey.Extensions.Result;
[ExcludeFromCodeCoverage]
public static partial class Extensions
{
#region ValueTask<Result<T>>
/// <inheritdoc cref="Map{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,TNew})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async ValueTask<Result<TNew>> Map<T, TNew>(this ValueTask<Result<T>> result,
Func<T, TNew> func)
=> (await result).Map(func);
/// <inheritdoc cref="Map{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,TNew})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async ValueTask<Result<TNew>> MapAsync<T, TNew>(this ValueTask<Result<T>> result,
Func<T, ValueTask<TNew>> func)
=> await (await result).MapAsync(func);
/// <inheritdoc cref="Then{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,Geekeey.Extensions.Result.Result{TNew}})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async ValueTask<Result<TNew>> Then<T, TNew>(this ValueTask<Result<T>> result,
Func<T, Result<TNew>> func)
=> (await result).Then(func);
/// <inheritdoc cref="Then{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,Geekeey.Extensions.Result.Result{TNew}})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async ValueTask<Result<TNew>> ThenAsync<T, TNew>(this ValueTask<Result<T>> result,
Func<T, ValueTask<Result<TNew>>> func)
=> await (await result).ThenAsync(func);
#endregion
#region Task<Result<T>>
/// <summary>
@ -59,34 +89,4 @@ public static partial class Extensions
=> await (await result).ThenAsync(func);
#endregion
#region ValueTask<Result<T>>
/// <inheritdoc cref="Map{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,TNew})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async ValueTask<Result<TNew>> Map<T, TNew>(this ValueTask<Result<T>> result,
Func<T, TNew> func)
=> (await result).Map(func);
/// <inheritdoc cref="Map{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,TNew})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async ValueTask<Result<TNew>> MapAsync<T, TNew>(this ValueTask<Result<T>> result,
Func<T, ValueTask<TNew>> func)
=> await (await result).MapAsync(func);
/// <inheritdoc cref="Then{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,Geekeey.Extensions.Result.Result{TNew}})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async ValueTask<Result<TNew>> Then<T, TNew>(this ValueTask<Result<T>> result,
Func<T, Result<TNew>> func)
=> (await result).Then(func);
/// <inheritdoc cref="Then{T,TNew}(System.Threading.Tasks.Task{Geekeey.Extensions.Result.Result{T}},System.Func{T,Geekeey.Extensions.Result.Result{TNew}})"/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async ValueTask<Result<TNew>> ThenAsync<T, TNew>(this ValueTask<Result<T>> result,
Func<T, ValueTask<Result<TNew>>> func)
=> await (await result).ThenAsync(func);
#endregion
}

View file

@ -46,8 +46,8 @@ public readonly partial struct Result<T>
/// <returns>A task completing with the result of applying either <paramref name="success"/> or
/// <paramref name="failure"/> on the success value or failure value of the result.</returns>
[Pure]
public async ValueTask<TResult> MatchAsync<TResult>(Func<T, ValueTask<TResult>> success, Func<Error, ValueTask<TResult>> failure)
=> _success ? await success(Value!) : await failure(Error!);
public ValueTask<TResult> MatchAsync<TResult>(Func<T, ValueTask<TResult>> success, Func<Error, ValueTask<TResult>> failure)
=> _success ? success(Value!) : failure(Error!);
/// <summary>
/// Asynchronously matches over the success value or failure value of the result and invokes an effectful action
@ -56,11 +56,8 @@ public readonly partial struct Result<T>
/// </summary>
/// <param name="success">The function to call with the success value of the result if the result is a success.</param>
/// <param name="failure">The function to call with the failure value of the result if the result is a failure.</param>
public async ValueTask SwitchAsync(Func<T, ValueTask> success, Func<Error, ValueTask> failure)
{
if (_success) await success(Value!);
else await failure(Error!);
}
public ValueTask SwitchAsync(Func<T, ValueTask> success, Func<Error, ValueTask> failure)
=> _success ? success(Value!) : failure(Error!);
}
public readonly partial struct Result<T>
@ -86,9 +83,6 @@ public readonly partial struct Result<T>
/// </summary>
/// <param name="success">The function to call with the success value of the result if the result is a success.</param>
/// <param name="failure">The function to call with the failure value of the result if the result is a failure.</param>
public async Task SwitchAsync(Func<T, Task> success, Func<Error, Task> failure)
{
if (_success) await success(Value!);
else await failure(Error!);
}
public Task SwitchAsync(Func<T, Task> success, Func<Error, Task> failure)
=> _success ? success(Value!) : failure(Error!);
}