OptTSomeIf Method

Returns back None if IsNone. Otherwise, returns Some(value) if validationCriterion(value) holds; None if it does not hold. Especially useful in fluent input validation.
C#
static Opt<Account> MaybeParseAccount(..) { }
static bool IsAccountNumberValid(int number) { }
static bool DoesAccountExist(string code) { }

var account = MaybeParseAccount(..)
                .Validate(acc => IsAccountNumberValid(acc.Number))
                .Validate(acc => DoesAccountExist(acc.Code));
// account will be Some(account) only if:
// - MaybeParseAccount returns Some(account), and further,
// - both IsAccountNumberValid and DoesAccountExist validation checks return true.

Definition

Namespace: Orx.Fun.Option
Assembly: Orx.Fun.Option (in Orx.Fun.Option.dll) Version: 1.2.1+ea79806fa5e0e04bfdaef2a1916930e75e2cde74
C#
public Opt<T> SomeIf(
	Func<T, bool> validationCriterion
)

Parameters

validationCriterion  FuncT, Boolean
Condition on the underlying value that should hold to get a Some, rather than None.

Return Value

OptT

See Also