Esempio n. 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)));
        }
Esempio n. 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));
 }
Esempio n. 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)));
        }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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(); }));
 }