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