Ejemplo n.º 1
0
        public void Action(Untrusted <string> input)
        {
            // only way of getting the value is through a ValidatorBase implementation.
            var value = new SanitizeStringValidator().Validate(input);

            DoStuff(value);
        }
 public static Try <string, double> Add(
     Untrusted <string> fst,
     Untrusted <string> snd
     ) =>
 from f in ParseToDouble(fst)
 from s in ParseToDouble(snd)
 select f + s;
Ejemplo n.º 3
0
        public static Try <string, double> Add(Untrusted <string> fst, Untrusted <string> snd)
        {
            Func <double, double, double> add = (a, b) => a + b;

            return(Try <string, Func <double, double, double> > .Of(add)
                   .Apply(ParseToDouble(fst))   // Try<FailedToParseDoubleException, Func<double, double>>
                   .Apply(ParseToDouble(snd))); // Try<FailedToParseDoubleException, double>
        }
Ejemplo n.º 4
0
 public static Try <string, double> Add(Untrusted <string> fst, Untrusted <string> snd)
 => ParseToDouble(fst).Match(
     success: f => ParseToDouble(snd).Match <Try <string, double> >(
         success: s => f + s,
         failure: e => e
         ),
     failure: e => e
     );
Ejemplo n.º 5
0
 public bool Untrusted_Unwraps_Value_In_Maybe_Based_On_Given_Validation(NonNull <object> x, Maybe <NonNull <object> > m)
 {
     return(Untrusted <object>
            .Wrap(x.Get)
            .Unwrap(_ => m.Select(o => o.Get))
            .Equals(Maybe <object> .Nothing)
            .Equals(m.Equals(Maybe <NonNull <object> > .Nothing)));
 }
        private static Option <double> ParseToDouble(Untrusted <string> source)
        {
            var result = 0d;

            return(source.Validate(
                       s => double.TryParse(s, out result),
                       onSuccess: _ => result
                       ));
        }
Ejemplo n.º 7
0
        public T Validate(Untrusted <T> untrusted)
        {
            if (!InnerValidate(untrusted.Value))
            {
                throw new ValidationException();
            }

            return(untrusted.Value);
        }
        private static Try <string, double> ParseToDouble(Untrusted <string> source)
        {
            var result = 0d;

            return(source.Validate(
                       s => double.TryParse(s, out result),
                       failure: s => $"Failed to parse '{s}' to double",
                       success: _ => result
                       ));
        }
Ejemplo n.º 9
0
 public bool Untrusted_Unwraps_Value_In_Result_Based_On_Given_Validation(
     NonNull <object> x,
     Result <NonNull <object>, NonNull <object> > m)
 {
     return(Untrusted <object>
            .Wrap(x)
            .Unwrap(_ => m)
            .GetOk()
            .Equals(Maybe <NonNull <object> > .Nothing)
            .Equals(m.GetOk().Equals(Maybe <NonNull <object> > .Nothing)));
 }
 public static Try <string, double> Add(
     Untrusted <string> fst,
     Untrusted <string> snd
     ) => ParseToDouble(fst).Bind(f => ParseToDouble(snd).Map(s => f + s));
Ejemplo n.º 11
0
 public static Option <double> Add(Untrusted <string> fst, Untrusted <string> snd)
 => Option.Of <Func <double, double, double> >((a, b) => a + b)
 .Apply(ParseToDouble(fst))           // Option<Func<double, double>>
 .Apply(ParseToDouble(snd));          // Option<double>