// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace Geekeey.Extensions.Result;
///
/// Extensions for or relating to .
///
[ExcludeFromCodeCoverage]
public static partial class Extensions
{
#region Task>
///
/// Maps the success value of the result object of the completed task using a mapping function, or does nothing if
/// the result object of the completed task is a failure.
///
/// A task object retunring a result object when completing.
/// The function used to map the success value.
/// The type of the object inside the result returned by the task.
/// The type of the new value.
/// A new result containing either the mapped success value or the failure value of the original
/// result.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async ValueTask> Map(this Task> result,
Func func)
=> (await result).Map(func);
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async Task> MapAsync(this Task> result,
Func> func)
=> await (await result).MapAsync(func);
///
/// Maps the success value of the result object of the completed task to a new result using a mapping function, or
/// does nothing if the result object of the completed task is a failure.
///
/// A task object retunring a result object when completing.
/// The function used to map the success value.
/// The type of the object inside the result returned by the task.
/// The type of the new value.
/// A new result containing either the mapped success value or the failure value of the original
/// result.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async Task> Then(this Task> result,
Func> func)
=> (await result).Then(func);
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async Task> ThenAsync(this Task> result,
Func>> func)
=> await (await result).ThenAsync(func);
#endregion
#region ValueTask>
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async Task> Map(this ValueTask> result,
Func func)
=> (await result).Map(func);
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async ValueTask> MapAsync(this ValueTask> result,
Func> func)
=> await (await result).MapAsync(func);
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// ReSharper disable once InconsistentNaming
public static async ValueTask> Then(this ValueTask> result,
Func> func)
=> (await result).Then(func);
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static async ValueTask> ThenAsync(this ValueTask> result,
Func>> func)
=> await (await result).ThenAsync(func);
#endregion
}