chore: small consistency improvements
All checks were successful
default / dotnet default workflow (8.0) (push) Successful in 34s
All checks were successful
default / dotnet default workflow (8.0) (push) Successful in 34s
This commit is contained in:
parent
b3ed128536
commit
75314d8f7c
3 changed files with 38 additions and 44 deletions
|
@ -45,7 +45,7 @@ public static partial class Extensions
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <seealso cref="Join{T}(System.Collections.Generic.IEnumerable{Geekeey.Extensions.Result.Result{T}})"/>
|
/// <seealso cref="Join{T}(System.Collections.Generic.IEnumerable{Geekeey.Extensions.Result.Result{T}})"/>
|
||||||
// ReSharper disable once InconsistentNaming
|
// 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);
|
_ = results.TryGetNonEnumeratedCount(out var count);
|
||||||
var list = new List<T>(count);
|
var list = new List<T>(count);
|
||||||
|
@ -70,7 +70,7 @@ public static partial class Extensions
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <seealso cref="Join{T}(System.Collections.Generic.IEnumerable{Geekeey.Extensions.Result.Result{T}})"/>
|
/// <seealso cref="Join{T}(System.Collections.Generic.IEnumerable{Geekeey.Extensions.Result.Result{T}})"/>
|
||||||
// ReSharper disable once InconsistentNaming
|
// 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);
|
_ = results.TryGetNonEnumeratedCount(out var count);
|
||||||
var list = new List<T>(count);
|
var list = new List<T>(count);
|
||||||
|
|
|
@ -12,6 +12,36 @@ namespace Geekeey.Extensions.Result;
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public static partial class Extensions
|
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>>
|
#region Task<Result<T>>
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -59,34 +89,4 @@ public static partial class Extensions
|
||||||
=> await (await result).ThenAsync(func);
|
=> await (await result).ThenAsync(func);
|
||||||
|
|
||||||
#endregion
|
#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
|
|
||||||
}
|
}
|
|
@ -46,8 +46,8 @@ public readonly partial struct Result<T>
|
||||||
/// <returns>A task completing with the result of applying either <paramref name="success"/> or
|
/// <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>
|
/// <paramref name="failure"/> on the success value or failure value of the result.</returns>
|
||||||
[Pure]
|
[Pure]
|
||||||
public async ValueTask<TResult> MatchAsync<TResult>(Func<T, ValueTask<TResult>> success, Func<Error, ValueTask<TResult>> failure)
|
public ValueTask<TResult> MatchAsync<TResult>(Func<T, ValueTask<TResult>> success, Func<Error, ValueTask<TResult>> failure)
|
||||||
=> _success ? await success(Value!) : await failure(Error!);
|
=> _success ? success(Value!) : failure(Error!);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asynchronously matches over the success value or failure value of the result and invokes an effectful action
|
/// 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>
|
/// </summary>
|
||||||
/// <param name="success">The function to call with the success value of the result if the result is a success.</param>
|
/// <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>
|
/// <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)
|
public ValueTask SwitchAsync(Func<T, ValueTask> success, Func<Error, ValueTask> failure)
|
||||||
{
|
=> _success ? success(Value!) : failure(Error!);
|
||||||
if (_success) await success(Value!);
|
|
||||||
else await failure(Error!);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly partial struct Result<T>
|
public readonly partial struct Result<T>
|
||||||
|
@ -86,9 +83,6 @@ public readonly partial struct Result<T>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="success">The function to call with the success value of the result if the result is a success.</param>
|
/// <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>
|
/// <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)
|
public Task SwitchAsync(Func<T, Task> success, Func<Error, Task> failure)
|
||||||
{
|
=> _success ? success(Value!) : failure(Error!);
|
||||||
if (_success) await success(Value!);
|
|
||||||
else await failure(Error!);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue