ConditionedConstraint

public class ConditionedConstraint<T> : PredicateConstraint<T>

A data type that links a Predicate to an Error that describes why the predicate evaluation has failed.

  • The number of conditions that must ….

    Declaration

    Swift

    public var conditionsCount: Int { get }
  • Create a new ConditionedConstraint instance

    Declaration

    Swift

    public override init<P>(predicate: P, error: Error) where T == P.InputType, P : Predicate

    Parameters

    predicate

    A Predicate to describes the evaluation rule.

    error

    An Error that describes why the evaluation has failed.

  • Create a new ConditionedConstraint instance

    Declaration

    Swift

    public override init<P>(predicate: P, error: @escaping (T) -> Error) where T == P.InputType, P : Predicate

    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.

  • Add a condition Constraint.

    Declaration

    Swift

    public func add<C>(condition: C) where T == C.InputType, C : Constraint

    Parameters

    constraint
  • Add a predefined list of conditional Constraints.

    Declaration

    Swift

    public func add<C>(conditions: [C]) where T == C.InputType, C : Constraint

    Parameters

    constraints

    [Constraint]

  • A an unsized list of conditional Constraints.

    Declaration

    Swift

    public func add<C>(conditions: C...) where T == C.InputType, C : Constraint

    Parameters

    constraints

    [Constraint]

  • Evaluates the input on the Predicate.

    Declaration

    Swift

    public override func evaluate(with input: T) -> ValidationResult

    Parameters

    input

    The input to be validated.

    Return Value

    .success if the input is valid,.failure containing the Summary of the failing Constraints otherwise.