Esempio n. 1
0
 public static ICanbe <I> Reinit <I>(this ICanbe <I> self, Func <I> def)
 {
     try
     {
         if (self.IsError)
         {
             return(Cons <I>(def()));
         }
         return(self);
     }
     catch (Exception exn) { return(Fail <I>(Error.From(exn))); }
 }
Esempio n. 2
0
 public static ICanbe <I> FailIf <I>(this ICanbe <I> self, Func <I, bool> func, string message, int errorcode = 0)
 {
     try
     {
         if (self.IsOk && func(self.Value))
         {
             return(Fail <I>(message, errorcode));
         }
         return(self);
     }
     catch (Exception exn) { return(Fail <I>(Error.From(exn))); }
 }
Esempio n. 3
0
 public static ICanbe <I> OnSucc <I>(this ICanbe <I> self, Action <I> func)
 {
     try
     {
         if (self.IsOk)
         {
             func(self.Value);
         }
         return(self);
     }
     catch (Exception exn) { return(Fail <I>(Error.From(exn))); }
 }
Esempio n. 4
0
 public static ICanbe <I> OnFail <I>(this ICanbe <I> self, Action <Error> func)
 {
     try
     {
         if (self.IsError)
         {
             func(self.Error);
         }
         return(self);
     }
     catch (Exception exn) { return(Fail <I>(Error.From(exn))); }
 }
Esempio n. 5
0
 public static ICanbe <O> Map <I, O>(this ICanbe <I> self, Func <I, O> func)
 => self.Bind(x => Cons(func(x)));
Esempio n. 6
0
 async public static Task <ICanbe <O> > Bind <I, O>(this ICanbe <I> self, Func <I, Task <ICanbe <O> > > func)
 {
     try { return(self.IsError ? Fail <O>(self.Error) : await func(self.Value)); }
     catch (Exception exn) { return(Fail <O>(Error.From(exn))); }
 }
Esempio n. 7
0
 public static ICanbe <I[]> FailOnEmpty <I>(this ICanbe <I[]> self, Func <I[], string> lazymessage, System.Net.HttpStatusCode code)
 => FailIf(self, (xs => xs == null || (!xs.Any())), lazymessage, (int)code);
Esempio n. 8
0
 public static ICanbe <I[]> FailOnEmpty <I>(this ICanbe <I[]> self, string message, System.Net.HttpStatusCode code)
 => FailOnEmpty(self, message, (int)code);
Esempio n. 9
0
 public static ICanbe <I[]> FailOnEmpty <I>(this ICanbe <I[]> self, string message, int code = 0)
 => self.FailIf(xs => xs == null || (!xs.Any()), message, code);
Esempio n. 10
0
 public static ICanbe <I> FailOnNull <I>(this ICanbe <I> self, Func <I, string> lazymessage, System.Net.HttpStatusCode code)
 => FailIf(self, (xs => xs == null), lazymessage, (int)code);
Esempio n. 11
0
 public static ICanbe <I> FailOnNull <I>(this ICanbe <I> self, string message, System.Net.HttpStatusCode code)
 => FailOnNull(self, message, (int)code);
Esempio n. 12
0
 public static ICanbe <I> FailOnNull <I>(this ICanbe <I> self, string message, int code = 0)
 => self.FailIf(xs => xs == null, message, code);
Esempio n. 13
0
 public static ICanbe <I> FailIf <I>(this ICanbe <I> self, Func <I, bool> func, Func <I, string> lazymessage, System.Net.HttpStatusCode errorcode)
 => FailIf <I>(self, func, lazymessage, (int)errorcode);
Esempio n. 14
0
 async public static Task <ICanbe <O> > Map <I, O>(this ICanbe <I> self, Func <I, Task <O> > func)
 => await self.Bind(async x => Cons(await func(x)));