示例#1
0
        /// <summary>
        /// SelectMany
        /// </summary>
        public static EitherStrict <L, VR> SelectMany <L, TR, UR, VR>(
            this EitherStrict <L, TR> self,
            Func <TR, EitherStrict <L, UR> > selector,
            Func <TR, UR, VR> projector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }
            if (projector == null)
            {
                throw new ArgumentNullException("projector");
            }

            if (self.IsLeft)
            {
                return(EitherStrict.Left <L, VR>(self.Left));
            }

            var res = selector(self.Right);

            if (res.IsLeft)
            {
                return(EitherStrict.Left <L, VR>(res.Left));
            }

            return(EitherStrict.Right <L, VR>(projector(self.Right, res.Right)));
        }
示例#2
0
 public static EitherStrict <L, D> M <L, A, B, C, D>(EitherStrict <L, A> ma, EitherStrict <L, B> mb, EitherStrict <L, C> mc, Func <A, B, C, D> liftFn)
 {
     return(from a in ma
            from b in mb
            from c in mc
            select liftFn(a, b, c));
 }
示例#3
0
        /// <summary>
        /// Select
        /// </summary>
        public static EitherStrict <L, UR> Select <L, TR, UR>(
            this EitherStrict <L, TR> self,
            Func <TR, UR> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            if (self.IsLeft)
            {
                return(EitherStrict.Left <L, UR>(self.Left));
            }

            return(EitherStrict.Right <L, UR>(selector(self.Right)));
        }
示例#4
0
 public static EitherStrict <L, U> M <L, R, U>(EitherStrict <L, R> m, Func <R, U> liftFn)
 {
     return(from v in m select liftFn(v));
 }
示例#5
0
 public static EitherStrict <L, C> M <L, A, B, C>(EitherStrict <L, A> ma, EitherStrict <L, B> mb, Func <A, B, C> liftFn)
 {
     return(from a in ma
            from b in mb
            select liftFn(a, b));
 }
示例#6
0
 /// <summary>
 /// If the result is left, it interprets it as an error and throws and exception.
 /// </summary>
 public static T ThrowIfError <T>(this EitherStrict <RestBusinessError, T> result)
 {
     return(result.Match(
                Right: v => v,
                Left: err => { throw err.ToHttpError().ToRestException(); }));
 }