ResTOkIf Method
Returns back the Err if this is Err.
Otherwise, returns Ok(value) if
condition(value) holds; Err if it does not hold.
Especially useful in fluent input validation.
static Res<Account> TryParseAccount(..) { }
static bool IsAccountNumberValid(int number) { }
static bool DoesAccountExist(string code) { }
var account = TryParseAccount(..)
.OkIf(acc => IsAccountNumberValid(acc.Number))
.OkIf(acc => DoesAccountExist(acc.Code));
// account will be Ok(account) only if:
// - TryParseAccount returns Ok(account), and further,
// - both IsAccountNumberValid and DoesAccountExist validation checks return true.
Namespace: Orx.Fun.ResultAssembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
public Res<T> OkIf(
Func<T, bool> condition,
string strOkCondition = ""
)
- condition FuncT, Boolean
- Condition on the underlying value that should hold to get an Ok, rather than Err.
- strOkCondition String (Optional)
- Name of the condition; to be appended to the error message if it does not hold. Omitting the argument will automatically be filled with the condition's expression in the caller side.
ResT