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

            return(otherVal);
        }
예제 #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)));
        }
예제 #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);
        }
예제 #4
0
 public static Opt <T> Some <T>(T val)
 {
     return(Opt <T> .Some(val));
 }
예제 #5
0
 public static Opt <T> None <T>()
 {
     return(Opt <T> .None());
 }