PredicateConstraint
public class PredicateConstraint<T> : Constraint
A data type that links a Predicate
to an Error
that describes why the predicate evaluation has failed.
-
Create a new
PredicateConstraint
instanceDeclaration
Swift
public init<P:Predicate>(predicate: P, error: @escaping (T)->Error) where P.InputType == T
Parameters
predicate
A
Predicate
to describes the evaluation rule.error
A generic closure that dynamically builds an
Error
to describe why the evaluation has failed. -
Evaluates the input on the
Predicate
.Declaration
Swift
public func evaluate(with input: T) -> Result
Parameters
input
The input to be validated.
Return Value
.valid
if the input is valid,.invalid
containing theResult.Summary
of the failingConstraint
s otherwise.