Exists

Returns true if the option IsSome and the predicate return true when applied it. Otherwise, returns false.

Parameters

Returns

Func<T, bool> predicate

Option<T> option

bool

Usage

When the Option<T> IsNone the results will be always false, Otherwise the predicate function will be applied to the Option and its returns will be the returned value.

When the option value IsSome and predicates returns true

Option<int> optionValue = 4;
bool result = optionValue.Exists(value => value % 2 == 0);

//result = true

When the option value IsSome and predicates returns false

Option<int> optionValue = 3;
bool result = optionValue.Exists(value => value % 2 == 0);

//result = false

When the option value IsNone

Option<int> optionValue = Option<int>.None();
bool result = 
    optionValue.Exists(value => value % 2 == 0);

//result = false

Last updated