Ejemplo n.º 1
0
        public static Result <TIn> ToResult <TIn>(this Maybe <TIn> maybe, Result.Error error) where TIn : class
        {
            if (maybe.HasNoValue)
            {
                return(Result.Fail <TIn>(error));
            }

            return(Result.Ok(maybe.Value));
        }
Ejemplo n.º 2
0
 public static Result <string> EnsureNotNullOrWhiteSpace(this Maybe <string> maybe, Result.Error error)
 {
     return(maybe.ToResult(error)
            .Ensure(name => !string.IsNullOrWhiteSpace(name), error));
 }
Ejemplo n.º 3
0
        public static Result <T> Ensure <T>(this Result <T> result, Func <T, bool> predicate, Result.Error error)
        {
            if (result.IsFailure)
            {
                return(result);
            }

            if (!predicate(result.Value))
            {
                return(Result.Fail <T>(error));
            }

            return(result);
        }