예제 #1
0
 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;
예제 #2
0
 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;
예제 #3
0
 public Task <Unit> Match(TryOptionAsync <A> opt, Action <A> Succ, Action Fail) =>
 opt.Match(
     Succ,
     None: Fail,
     Fail: _ => Fail());
예제 #4
0
 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);
예제 #8
0
 public Task <Unit> MatchAsync(TryOptionAsync <A> opt, Action <A> Some, Action None) =>
 opt.Match(
     Some,
     None: () => None(),
     Fail: _ => None());
예제 #9
0
 public Task <B> MatchUnsafeAsync <B>(TryOptionAsync <A> opt, Func <A, Task <B> > Some, Func <Task <B> > None) =>
 opt.Match(
     Some,
     None: () => None(),
     Fail: _ => None());
예제 #10
0
 public Task <B> MatchAsync <B>(TryOptionAsync <A> opt, Func <A, B> Some, Func <B> None) =>
 opt.Match(
     Some,
     None: () => None(),
     Fail: _ => None());
예제 #11
0
 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);