1717/// predicates are simple wrappers around closures to provide static type information and
1818/// allow composition and wrapping of existing behaviors.
1919public struct Predicate < T> {
20- fileprivate var matcher : ( Expression < T > ) throws -> PredicateResult
20+ fileprivate let matcher : @ Sendable ( Expression < T > ) throws -> PredicateResult
2121
2222 /// Constructs a predicate that knows how take a given value
23- public init ( _ matcher: @escaping ( Expression < T > ) throws -> PredicateResult ) {
23+ public init ( _ matcher: @escaping @ Sendable ( Expression < T > ) throws -> PredicateResult ) {
2424 self . matcher = matcher
2525 }
2626
@@ -33,26 +33,28 @@ public struct Predicate<T> {
3333 }
3434}
3535
36+ extension Predicate : Sendable where T: Sendable { }
37+
3638/// Provides convenience helpers to defining predicates
3739extension Predicate {
3840 /// Like Predicate() constructor, but automatically guard against nil (actual) values
39- public static func define( matcher: @escaping ( Expression < T > ) throws -> PredicateResult ) -> Predicate < T > {
41+ public static func define( matcher: @escaping @ Sendable ( Expression < T > ) throws -> PredicateResult ) -> Predicate < T > {
4042 return Predicate< T> { actual in
4143 return try matcher ( actual)
4244 } . requireNonNil
4345 }
4446
4547 /// Defines a predicate with a default message that can be returned in the closure
4648 /// Also ensures the predicate's actual value cannot pass with `nil` given.
47- public static func define( _ message: String = " match " , matcher: @escaping ( Expression < T > , ExpectationMessage ) throws -> PredicateResult ) -> Predicate < T > {
49+ public static func define( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > , ExpectationMessage ) throws -> PredicateResult ) -> Predicate < T > {
4850 return Predicate< T> { actual in
4951 return try matcher ( actual, . expectedActualValueTo( message) )
5052 } . requireNonNil
5153 }
5254
5355 /// Defines a predicate with a default message that can be returned in the closure
5456 /// Unlike `define`, this allows nil values to succeed if the given closure chooses to.
55- public static func defineNilable( _ message: String = " match " , matcher: @escaping ( Expression < T > , ExpectationMessage ) throws -> PredicateResult ) -> Predicate < T > {
57+ public static func defineNilable( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > , ExpectationMessage ) throws -> PredicateResult ) -> Predicate < T > {
5658 return Predicate< T> { actual in
5759 return try matcher ( actual, . expectedActualValueTo( message) )
5860 }
@@ -64,7 +66,7 @@ extension Predicate {
6466 /// error message.
6567 ///
6668 /// Also ensures the predicate's actual value cannot pass with `nil` given.
67- public static func simple( _ message: String = " match " , matcher: @escaping ( Expression < T > ) throws -> PredicateStatus ) -> Predicate < T > {
69+ public static func simple( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > ) throws -> PredicateStatus ) -> Predicate < T > {
6870 return Predicate< T> { actual in
6971 return PredicateResult ( status: try matcher ( actual) , message: . expectedActualValueTo( message) )
7072 } . requireNonNil
@@ -74,21 +76,21 @@ extension Predicate {
7476 /// error message.
7577 ///
7678 /// Unlike `simple`, this allows nil values to succeed if the given closure chooses to.
77- public static func simpleNilable( _ message: String = " match " , matcher: @escaping ( Expression < T > ) throws -> PredicateStatus ) -> Predicate < T > {
79+ public static func simpleNilable( _ message: String = " match " , matcher: @escaping @ Sendable ( Expression < T > ) throws -> PredicateStatus ) -> Predicate < T > {
7880 return Predicate< T> { actual in
7981 return PredicateResult ( status: try matcher ( actual) , message: . expectedActualValueTo( message) )
8082 }
8183 }
8284}
8385
8486// The Expectation style intended for comparison to a PredicateStatus.
85- public enum ExpectationStyle {
87+ public enum ExpectationStyle : Sendable {
8688 case toMatch, toNotMatch
8789}
8890
8991/// The value that a Predicates return to describe if the given (actual) value matches the
9092/// predicate.
91- public struct PredicateResult {
93+ public struct PredicateResult : Sendable {
9294 /// Status indicates if the predicate matches, does not match, or fails.
9395 public var status : PredicateStatus
9496 /// The error message that can be displayed if it does not match
@@ -113,7 +115,7 @@ public struct PredicateResult {
113115}
114116
115117/// PredicateStatus is a trinary that indicates if a Predicate matches a given value or not
116- public enum PredicateStatus {
118+ public enum PredicateStatus : Sendable {
117119 /// Matches indicates if the predicate / matcher passes with the given value
118120 ///
119121 /// For example, `equals(1)` returns `.matches` for `expect(1).to(equal(1))`.
@@ -167,7 +169,7 @@ public enum PredicateStatus {
167169
168170extension Predicate {
169171 // Someday, make this public? Needs documentation
170- internal func after( f: @escaping ( Expression < T > , PredicateResult ) throws -> PredicateResult ) -> Predicate < T > {
172+ internal func after( f: @escaping @ Sendable ( Expression < T > , PredicateResult ) throws -> PredicateResult ) -> Predicate < T > {
171173 // swiftlint:disable:previous identifier_name
172174 return Predicate { actual -> PredicateResult in
173175 let result = try self . satisfies ( actual)
@@ -193,7 +195,7 @@ extension Predicate {
193195#if canImport(Darwin)
194196import class Foundation. NSObject
195197
196- public typealias PredicateBlock = ( _ actualExpression: Expression < NSObject > ) throws -> NMBPredicateResult
198+ public typealias PredicateBlock = @ Sendable ( _ actualExpression: Expression < NSObject > ) throws -> NMBPredicateResult
197199
198200public class NMBPredicate : NSObject {
199201 private let predicate : PredicateBlock
@@ -202,7 +204,7 @@ public class NMBPredicate: NSObject {
202204 self . predicate = predicate
203205 }
204206
205- func satisfies( _ expression: @escaping ( ) throws -> NSObject ? , location: SourceLocation ) -> NMBPredicateResult {
207+ func satisfies( _ expression: @escaping @ Sendable ( ) throws -> NSObject ? , location: SourceLocation ) -> NMBPredicateResult {
206208 let expr = Expression ( expression: expression, location: location)
207209 do {
208210 return try self . predicate ( expr)
@@ -238,7 +240,7 @@ extension PredicateResult {
238240 }
239241}
240242
241- final public class NMBPredicateStatus : NSObject {
243+ final public class NMBPredicateStatus : NSObject , Sendable {
242244 private let status : Int
243245 private init ( status: Int ) {
244246 self . status = status
0 commit comments