ensure
This function assesses if the provided verificable
matches or not the provided predicate
.
Returns the underlying value if predicate
is matched, otherwise throws VerificaException
containing list of VerificaError
objects.
Examples:
First, let's define an example object user
that we want to verify and wrap it with asVerificable():
Then we can call ensure()
method providing the Verificable
object to be checked, and the Predicate
defining the validation rule. If value behind the Verificable
object doesn't match the Predicate
, ensure()
will throw VerificaException
containing and array of VerificaError
objects. If the value matches the Predicate
, ensure()
will return the value directly.
Last updated
Was this helpful?