37 lines
891 B
C#
37 lines
891 B
C#
using LanguageExt.Common;
|
|
|
|
namespace W542.GandalfReborn.Extensions;
|
|
|
|
public static class ResultExtensions
|
|
{
|
|
public static T GetValue<T>(this Result<T> result)
|
|
{
|
|
return result.Match<T?>(
|
|
x => x,
|
|
_ => default
|
|
)!;
|
|
}
|
|
|
|
public static Result<T> AsResult<T>(this T result)
|
|
{
|
|
return new Result<T>(result);
|
|
}
|
|
|
|
public static Result<TOutbound> AsErrorResult<TOutbound, TInbound>(this Result<TInbound> result)
|
|
{
|
|
return result.Match<Result<TOutbound>>(
|
|
_ => default,
|
|
e => new Result<TOutbound>(e)
|
|
);
|
|
}
|
|
|
|
public static Result<T> AsErrorResult<T>(this Result<T> result)
|
|
{
|
|
return result.AsErrorResult<T, T>();
|
|
}
|
|
|
|
public static Result<T> AsErrorResult<T>(this string? errorMessage)
|
|
{
|
|
return new Result<T>(new Exception(errorMessage));
|
|
}
|
|
} |