AnyConstraint

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

A type-erased Constraint.

enum Failure: Error {
    case notEven
}

let constraint = BlockConstraint<Int, Failure> {
    $0 % 2 == 0
} errorBuilder: {
    .notEven
}

let anyConstraint = AnyConstraint(constraint)
anyConstraint.evaluate(with: 3)
  • Declaration

    Swift

    public typealias InputType = T
  • Declaration

    Swift

    public typealias ErrorType = E
  • Creates a type-erased Constraint that wraps the given instance.

    Declaration

    Swift

    public init<C>(_ constraint: C) where T == C.InputType, E == C.ErrorType, C : Constraint
  • Evaluates the input against the receiver.

    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.