/// <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))); }
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)); }
/// <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))); }
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)); }
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)); }
/// <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(); })); }