BlockPredicate
public struct BlockPredicate<T> : Predicate
The BlockPredicate
struct defines a closure based condition used to evaluate generic inputs.
let predicate = BlockPredicate<Int> {
$0 % 2 == 0
}
let isEven = even.evaluate(with: 2)
-
Declaration
Swift
public typealias InputType = T
-
Returns a new
BlockPredicate
instance.let predicate = BlockPredicate<Int> { $0 % 2 == 0 } let isEven = even.evaluate(with: 2)
Declaration
Swift
public init(evaluationBlock: @escaping (_ input: InputType) -> Bool)
Parameters
evaluationBlock
A closure describing a custom validation condition.
input
The input against which to evaluate the receiver.
-
Returns a
Boolean
value that indicates whether a given input matches the evaluation closure 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 validation closure specified by the receiver, otherwisefalse
.