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))); } }
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))); } }
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))); } }
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))); } }
public static ICanbe <O> Map <I, O>(this ICanbe <I> self, Func <I, O> func) => self.Bind(x => Cons(func(x)));
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))); } }
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);
public static ICanbe <I[]> FailOnEmpty <I>(this ICanbe <I[]> self, string message, System.Net.HttpStatusCode code) => FailOnEmpty(self, message, (int)code);
public static ICanbe <I[]> FailOnEmpty <I>(this ICanbe <I[]> self, string message, int code = 0) => self.FailIf(xs => xs == null || (!xs.Any()), message, code);
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);
public static ICanbe <I> FailOnNull <I>(this ICanbe <I> self, string message, System.Net.HttpStatusCode code) => FailOnNull(self, message, (int)code);
public static ICanbe <I> FailOnNull <I>(this ICanbe <I> self, string message, int code = 0) => self.FailIf(xs => xs == null, message, code);
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);
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)));