public static Validation <ErrorMsg, Unit> AccountMustNotExist( this TryOptionAsync <AccountState> self) => self .Match( Fail: _ => Fail <ErrorMsg, Unit>("Unable to get account info"), Some: acc => Fail <ErrorMsg, Unit>($"Id {acc.AccountId} already exists"), None: () => Success <ErrorMsg, Unit>(unit) ) .Result;
public static Validation <ErrorMsg, AccountState> AccountMustExist( this TryOptionAsync <AccountState> self) => self .Match( Fail: _ => Fail <ErrorMsg, AccountState>("Unable to get account info"), Some: Success <ErrorMsg, AccountState>, None: () => Fail <ErrorMsg, AccountState>("Account does not exist") ) .Result;
public Task <Unit> Match(TryOptionAsync <A> opt, Action <A> Succ, Action Fail) => opt.Match( Succ, None: Fail, Fail: _ => Fail());
public Task <B> Match <B>(TryOptionAsync <A> opt, Func <A, B> Succ, Func <B> Fail) => opt.Match( Succ, None: Fail, Fail: _ => Fail());
/// <summary> /// Pattern matches the three possible states of the Try computation /// </summary> /// <typeparam name="R">Type of the resulting bound value</typeparam> /// <param name="Some">Delegate to invoke if the Try computation completes successfully</param> /// <param name="None">Delegate to invoke if the Try computation completes successfully but returns no value</param> /// <param name="Fail">Delegate to invoke if the Try computation fails</param> /// <returns>The result of either the Succ, None, or Fail delegate</returns> public static Task <Unit> match <A>(TryOptionAsync <A> self, Action <A> Some, Action None, Action <Exception> Fail) => self.Match(Some, None, Fail);
public static Task <R> match <A, R>(TryOptionAsync <A> self, Func <A, R> Some, Func <R> None, R Fail) => self.Match(Some, None, Fail);
public Task <B> Fail(Func <Exception, B> f) => value.Match(succHandler, noneHandler, f);
public Task <Unit> MatchAsync(TryOptionAsync <A> opt, Action <A> Some, Action None) => opt.Match( Some, None: () => None(), Fail: _ => None());
public Task <B> MatchUnsafeAsync <B>(TryOptionAsync <A> opt, Func <A, Task <B> > Some, Func <Task <B> > None) => opt.Match( Some, None: () => None(), Fail: _ => None());
public Task <B> MatchAsync <B>(TryOptionAsync <A> opt, Func <A, B> Some, Func <B> None) => opt.Match( Some, None: () => None(), Fail: _ => None());
public static Task <R> match <A, R>(TryOptionAsync <A> self, Func <A, Task <R> > Some, Func <Task <R> > None, Func <Exception, Task <R> > Fail) => self.Match(Some, None, Fail);