Esempio n. 1
0
        public static void Ex2List()
        {
            var l1 = "[ 1 2 2.5 abc -5 14 ]".ToStringEnumF()
                     .Map(x => ToNatural(x))
                     .Filter(x => x.IsSome)
                     .Map(x => x.Value);

            WriteLine(l1.ToStringF());

            var o1 = ToNatural("1");

            WriteLine(o1);

            var o2 = ToNatural("abc");

            WriteLine(o2);

            var o3 = OptionF <OptionF <int> > .Some(o1);

            WriteLine(o3);

            var o4 = o3.Bind((OptionF <int> x) => x);

            WriteLine(o4.ToStringF()); // [ 1 ]

            var l2 = new OptionF <int>[] { o1, o2, o1, o2 }.AsEnumerable();
            var l3 = l2.Filter(x => x.IsSome).Map(x => x.Value); // [ 1 1 ]

            WriteLine(l3.ToStringF());
        }
Esempio n. 2
0
 public static OptionF <Age> FromInt(int age)
 {
     if (age > 0 && age < 120)
     {
         return(OptionF <Age> .Some(new Age(age)));
     }
     else
     {
         return(OptionF <Age> .None());
     }
 }
Esempio n. 3
0
 private static OptionF <int> ToPassingGrade(int n)
 {
     if (n >= 5 && n <= 10)
     {
         return(OptionF <int> .Some(n));
     }
     else
     {
         return(OptionF <int> .None());
     }
 }
Esempio n. 4
0
 private static OptionF <string> StringNotNumber(string s)
 {
     if (double.TryParse(s, out double d))
     {
         return(OptionF <string> .None());
     }
     else
     {
         return(OptionF <string> .Some(s));
     }
 }
Esempio n. 5
0
        private static OptionF <double> ToRealNumber(string s)
        {
            bool ok = double.TryParse(s, out double result);

            if (ok)
            {
                return(OptionF <double> .Some(result));
            }
            else
            {
                return(OptionF <double> .None());
            }
        }
Esempio n. 6
0
        private static OptionF <int> ToNatural(string s)
        {
            bool ok = Int32.TryParse(s, out int result);

            if (!ok)
            {
                return(OptionF <int> .None());
            }
            else if (result >= 0)
            {
                return(OptionF <int> .Some(result));
            }
            else
            {
                return(OptionF <int> .None());
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the ExpertMatchF class.
 /// </summary>
 /// <param name="option">An option object that will be used for pattern matching.</param>
 public ExpertMatchF(OptionF <T> option)
 {
     _option = option;
 }