Exists
Returns true if the given predicate functions return true when applied to either value. Otherwise, returns false.
ParĂ¢metros
Retorno
Func<TRight, bool> predicateWhenRight
Func<TLeft, bool> predicateWhenLeft
Either<TLeft, TRight> either
bool
Usage
When the Either IsLeft, the result will be the return of predicateWhenLeft function, otherwise will be the return of predicateWhenRight.
When Either IsRight and predicate returns true
Either<string, int> either = 20;
bool result =
either.Exists(
right => right == 20,
left => left == "Hello World");
//result = trueWhen Either IsLeft and predicate returns true
Either<string, int> either = "Hello World";
bool result =
either.Exists(
right => right == 20,
left => left == "Hello World");
//result = trueWhen Either IsRight and predicate returns false
One sided approach
You can also use the ExistsLeft and ExistsRight to produce the same results, but with these methods the predicated is applied just to one of the possible values.
When the target type is different from Either current value the result always will be false
ExistsRight when Either IsRight
ExistsLeft when Either IsRight
Last updated
Was this helpful?