ConstraintSet

public struct ConstraintSet<T>

A generic collection of Constraints on which an input can be validated on.

  • Returns the number of constraints in collection

    Declaration

    Swift

    public var count: Int { get }
  • Create a new ConstraintSet instance

    Declaration

    Swift

    public init()
  • Create a new ConstraintSet instance populated with a predefined list of Constraints

    Declaration

    Swift

    public init<C>(constraints: [C]) where T == C.InputType, C : Constraint

    Parameters

    constraints

    [Constraint]

  • Create a new ConstraintSet instance populated with a unsized list of Constraints

    Declaration

    Swift

    public init<C>(constraints: C...) where T == C.InputType, C : Constraint

    Parameters

    constraints

    [Constraint]

  • Evaluates the input on all Constraints until the first fails.

    Declaration

    Swift

    public func evaluateAny(input: T) -> Result

    Parameters

    input

    The input to be validated.

    Return Value

    .valid if the input is valid, .invalid containing the Error registered with the failing Constraint otherwise.

  • Evaluates the input on all `Constraints in the collection.

    Declaration

    Swift

    public func evaluateAll(input: T) -> Result

    Parameters

    input

    The input to be validated.

    Return Value

    An array of Result elements, indicating the evaluation result of each Constraint in collection.

  • Builds a PredicateConstraint instance and adds it to the generic collection of constraints.

    Declaration

    Swift

    public mutating func add<P>(predicate: P, error: Error) where T == P.InputType, P : Predicate

    Parameters

    predicate

    A Predicate to describes the evaluation rule.

    message

    An Error that describes why the evaluation has failed.