Код: Выделить всё
using LanguageExt;
using LanguageExt.Pipes;
using static LanguageExt.Prelude;
namespace ApplinxChannel.Api;
public class CompositeDelegateHandler(
Map mapToClean, IEnumerable validators)
{
public Aff Validate(TRequest request)
{
return validators
.Select(v => v(request))
.TraverseSerial(task => task)
.Match(
Succ: Validation.Success(mapToClean(request)),
Fail: (e) => Validation.Fail(Seq1(new FieldError("", e.Message)))
);
}
}`
Код: Выделить всё
`using LanguageExt;
using LanguageExt.Common;
using static LanguageExt.Prelude;
namespace ApplinxChannel.Api;
internal static class Validation
{
internal static Eff Validate(TRequest request)
where TRuntime : struct,
HasValidator
where TRequest : notnull
where TClean : notnull
{
return from runtime in Eff(identity)
let clean = runtime.Validate(request).Bind(x => x.ToEff(errors =>
errors.Aggregate(Error.New("Errors have occurred when " +
"validating your data. See other errors for details."), (e1, e2) => e1.Append(e2))))
select clean;
}
}
`
Инструкция return в методе Eff Validate возвращает Eff c.ToEff(errors =>
errors.Aggregate(Error.New("Errors have occurred when " +
"validating your data. See other errors for details."), (e1, e2) => e1.Append(e2))))
select eff.Bind(aa => aa.Map(e => e));`
[/code]
Но это дает мне Aff при последнем выборе, который не соответствует окончательному ожидаемому Eff, потому что это создает Eff
Ожидается, что в конечном итоге получится объект TClean внутри метода Validate . Это создает ошибку компиляции, поскольку сигнатура метода Validate определена как Eff Validate, а оператор return создает объект типа Eff
Любая идея или предложение приветствуется.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ary-with-c
Мобильная версия