Add initial project structure with Result type and extension methods

This commit is contained in:
2025-07-23 08:43:59 +02:00
commit 94ad6e57d7
7 changed files with 249 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
namespace Rehlert.RoP.Extensions;
public static class FallbackExtensions
{
public static TIn FallbackWith<TIn, TErr>(this Result<TIn, TErr> value, TIn defaultValue)
{
var result = value.Match(
ok => ok.Value,
_ => defaultValue
);
return result;
}
public static async Task<TIn> FallbackWith<TIn, TErr>(
this Task<Result<TIn, TErr>> value,
TIn defaultValue
)
{
var valRes = await value;
var result = valRes.Match(
ok => ok.Value,
_ => defaultValue
);
return result;
}
}