public virtual async Task <Maybe <ReducerResult <TData> > > Reduce(Maybe <MutatingContext <TData> > state, IStateAction action) { try { var typedAction = (TAction)action; if (Validator == null) { return(await Reduce(state, (TAction)action)); } var result = await Validator.ValidateAsync(typedAction); return(!result.IsValid ? ReducerResult.Fail(state, result.Errors.Select(f => f.ErrorMessage)) : await Reduce(state, (TAction)action)); } catch (Exception e) { return(ReducerResult.Fail(state, new[] { e.Message })); } }
protected Task <Maybe <ReducerResult <TData> > > FailAsync(Maybe <MutatingContext <TData> > data, IEnumerable <string> errors) => Task.FromResult(ReducerResult.Fail(data, errors));
protected Task <Maybe <ReducerResult <TData> > > SucessAsync(Maybe <MutatingContext <TData> > data) => Task.FromResult(ReducerResult.Sucess(data));
protected Maybe <ReducerResult <TData> > Fail(Maybe <MutatingContext <TData> > data, IEnumerable <string> errors) => ReducerResult.Fail(data, errors);
protected Maybe <ReducerResult <TData> > Sucess(Maybe <MutatingContext <TData> > data) => ReducerResult.Sucess(data);