Files
ersatztv/ErsatzTV.Core/LanguageExtensions.cs
T
Jason DoveandGitHub 7e30444857 dependencies and code cleanup (#2117)
* fix validation in new form layout

* pin mediatr to last oss version

* update dependencies

* cleanup code in core

* cleanup code in ffmpeg

* cleanup code in infra

* cleanup code in scanner

* cleanup code in application

* cleanup main code

* cleanup test code

* solution-wide code cleanup
2025-07-06 15:56:17 +00:00

43 lines
1.5 KiB
C#

using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
namespace ErsatzTV.Core;
[SuppressMessage("ReSharper", "VSTHRD003")]
public static class LanguageExtensions
{
public static Either<BaseError, TR> ToEither<TR>(this Validation<BaseError, TR> validation) =>
validation.ToEither().MapLeft(errors => errors.Join());
public static Task<Either<BaseError, TR>> ToEitherAsync<TR>(this Validation<BaseError, Task<TR>> validation) =>
validation.ToEither()
.MapLeft(errors => errors.Join())
.MapAsync<BaseError, Task<TR>, TR>(e => e);
public static Task<Either<BaseError, TR>> Apply<T, TR>(
this Validation<BaseError, T> validation,
Func<T, Task<TR>> task) =>
validation.Match<Task<Either<BaseError, TR>>>(
async t => await task(t),
error => Task.FromResult(Left<BaseError, TR>(error.Join())));
[SuppressMessage("Usage", "CA2254:Template should be a static expression")]
public static Task<T> LogFailure<T>(
this TryAsync<T> tryAsync,
T defaultValue,
ILogger logger,
string message,
params object[] args) =>
tryAsync.IfFail(ex =>
{
logger.LogError(ex, message, args);
return defaultValue;
});
public static Task<Unit> LogFailure(
this TryAsync<Unit> tryAsync,
ILogger logger,
string message,
params object[] args) => LogFailure(tryAsync, Unit.Default, logger, message, args);
}