feat: fix inconsistent naming of transformation functions

Fix naming of transformation functions like `Nap` and `Then` when handling `Task` or `ValueTask` as a result of the transformation. If the transformation function supplied to the `Map` or `Then` function returns a `Task` or `ValueTask`, now these functions always have the `Async` suffix in their name.
If the function is an extension function which operates on a `Task<Result<T>>` or `ValueTask<Result<T>>` and does not fulfil the contracts with the task result of the transformation, the function does **not** have the `Async` suffix.
This commit is contained in:
Louis Seubert 2024-05-01 17:55:07 +02:00
parent 1a8737ffa5
commit fb6e06952c
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD

View file

@ -22,13 +22,14 @@ public static partial class Extensions
/// <returns>A new result containing either the mapped success value or the failure value of the original
/// result.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async ValueTask<Result<TNew>> Map<T, TNew>(this Task<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 Task<Result<TNew>> Map<T, TNew>(this Task<Result<T>> result,
public static async Task<Result<TNew>> MapAsync<T, TNew>(this Task<Result<T>> result,
Func<T, ValueTask<TNew>> func)
=> await (await result).MapAsync(func);
@ -43,13 +44,14 @@ public static partial class Extensions
/// <returns>A new result containing either the mapped success value or the failure value of the original
/// result.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async Task<Result<TNew>> Then<T, TNew>(this Task<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 Task<Result<TNew>> Then<T, TNew>(this Task<Result<T>> result,
public static async Task<Result<TNew>> ThenAsync<T, TNew>(this Task<Result<T>> result,
Func<T, ValueTask<Result<TNew>>> func)
=> await (await result).ThenAsync(func);
@ -59,25 +61,27 @@ public static partial class Extensions
/// <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 Task<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>> Map<T, TNew>(this ValueTask<Result<T>> result,
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>> Then<T, TNew>(this ValueTask<Result<T>> result,
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);