AnyPredicate

public struct AnyPredicate<T> : Predicate

A type-erased Predicate.

let odd = BlockPredicate<Int> {
   $0 % 2 != 0
}

let anyOdd = AnyPredicate<Int>(odd)
let isOdd = anyOdd.evaluate(with: 3)
  • A type that provides information about what kind of values the predicate can be evaluated with.

    Declaration

    Swift

    public typealias InputType = T
  • Creates a type-erased Predicate that wraps the given instance.

    let odd = BlockPredicate<Int> {
       $0 % 2 != 0
    }
    
    let anyOdd = AnyPredicate<Int>(odd)
    let isOdd = anyOdd.evaluate(with: 3)
    

    Declaration

    Swift

    public init<P>(_ predicate: P) where T == P.InputType, P : Predicate
  • Returns a Boolean value that indicates whether a given input matches the conditions specified by the receiver.

    Declaration

    Swift

    public func evaluate(with input: InputType) -> Bool

    Parameters

    input

    The input against which to evaluate the receiver.

    Return Value

    true if input matches the conditions specified by the receiver, false otherwise.