PredicateConstraint

public struct PredicateConstraint<T, E> : Constraint where E : Error

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

  • Declaration

    Swift

    public typealias InputType = T
  • Declaration

    Swift

    public typealias ErrorType = E
  • Create a new PredicateConstraint instance

    Declaration

    Swift

    public init<P>(_ predicate: P, error: E) 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 PredicateConstraint instance

    Declaration

    Swift

    public init<P>(_ predicate: P, errorBuilder: @escaping (T) -> E) 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.

  • Create a new PredicateConstraint instance

    Declaration

    Swift

    public init<P>(_ predicate: P, errorBuilder: @escaping () -> E) 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.

  • Create a new PredicateConstraint instance

    Declaration

    Swift

    public init<P>(_ predicateBuilder: @escaping () -> P, errorBuilder: @escaping (T) -> E) where T == P.InputType, P : Predicate

    Parameters

    predicateBuilder

    A a closure that dynamically builds a Predicate to describes the evaluation rule.

    error

    A generic closure that dynamically builds an Error to describe why the evaluation has failed.

  • Create a new PredicateConstraint instance

    Declaration

    Swift

    public init<P>(_ predicateBuilder: @escaping () -> P, errorBuilder: @escaping () -> E) where T == P.InputType, P : Predicate

    Parameters

    predicateBuilder

    A a closure that dynamically builds 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<Void, Summary<E>>

    Parameters

    input

    The input to be validated.

    Return Value

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

  • Create a new PredicateConstraint instance with an underlying BlockPredicate.

    Declaration

    Swift

    public init(_ evaluationBlock: @escaping (T) -> Bool, errorBuilder: @escaping () -> E)

    Parameters

    evaluationBlock

    A closure describing a custom validation condition.

    error

    A generic closure that dynamically builds an Error to describe why the evaluation has failed.

  • Create a new PredicateConstraint instance with an underlying BlockPredicate.

    Declaration

    Swift

    public init(_ evaluationBlock: @escaping (T) -> Bool, errorBuilder: @escaping (T) -> E)

    Parameters

    evaluationBlock

    A closure describing a custom validation condition.

    errorBuilder

    A generic closure that dynamically builds an Error to describe why the evaluation has failed.