diff --git a/Sources/WhereClauseType.swift b/Sources/WhereClauseType.swift index 6c28131..38ece53 100644 --- a/Sources/WhereClauseType.swift +++ b/Sources/WhereClauseType.swift @@ -21,3 +21,42 @@ public protocol WhereClauseType: AnyWhereClause { */ associatedtype ObjectType: DynamicObject } + +public extension WhereClauseType { + + /** + Combines two `Where` predicates together using `AND` operator. + - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types. + */ + public static func && (left: Self, right: TWhere) -> Self { + + return Self.init(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) + } + + /** + Combines two `Where` predicates together using `AND` operator. + - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows AND'ing clauses of unrelated `DynamicObject` types. + */ + public static func && (left: TWhere, right: Self) -> Self { + + return Self.init(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) + } + + /** + Combines two `Where` predicates together using `OR` operator. + - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types. + */ + public static func || (left: Self, right: TWhere) -> Self { + + return Self.init(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) + } + + /** + Combines two `Where` predicates together using `OR` operator. + - Warning: This operator overload is a workaround for Swift generics' inability to constrain by inheritance (https://bugs.swift.org/browse/SR-5213). In effect, this is less type-safe than other overloads because it allows OR'ing clauses of unrelated `DynamicObject` types. + */ + public static func || (left: TWhere, right: Self) -> Self { + + return Self.init(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) + } +}