Example #1
0
        public static T?OrNull <T>(this Opt <T> opt, T?otherVal) where T : struct
        {
            if (opt.IsSome)
            {
                return(opt.Val);
            }

            return(otherVal);
        }
Example #2
0
        public static Opt <V> Ap <T, U, V>(Func <T, U, V> f, Opt <T> v1, Opt <U> v2)
        {
            if (v1.IsNone)
            {
                return(Opt <V> .None());
            }
            if (v2.IsNone)
            {
                return(Opt <V> .None());
            }

            return(Opt <V> .Some(f(v1.Val, v2.Val)));
        }
Example #3
0
        public static Opt <T> Some(T val)
        {
            if (val == null)
            {
                throw new ArgumentNullException(nameof(val), "Cannot supply a NULL value to the Opt.Some() constructor.");
            }

            var opt = new Opt <T> {
                IsSome = true, _val = val
            };

            return(opt);
        }
Example #4
0
 public static Opt <T> Some <T>(T val)
 {
     return(Opt <T> .Some(val));
 }
Example #5
0
 public static Opt <T> None <T>()
 {
     return(Opt <T> .None());
 }