From 9ff1c9d54584115565f0dc5c69c2a2aa56c4663c Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 19 Feb 2017 20:05:23 +0900 Subject: [PATCH] declare operators as static functions --- .../Concrete Clauses/OrderBy.swift | 27 ++++++++----- .../Concrete Clauses/Where.swift | 40 +++++++++++-------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift b/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift index 76bb49d..692a8fe 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/OrderBy.swift @@ -27,17 +27,6 @@ import Foundation import CoreData -public func + (left: OrderBy, right: OrderBy) -> OrderBy { - - return OrderBy(left.sortDescriptors + right.sortDescriptors) -} - -public func += (left: inout OrderBy, right: OrderBy) { - - left = left + right -} - - // MARK: - KeyPath public typealias KeyPath = String @@ -69,6 +58,22 @@ public enum SortKey { */ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable { + /** + Combines two `OrderBy` sort descriptors together + */ + public static func + (left: OrderBy, right: OrderBy) -> OrderBy { + + return OrderBy(left.sortDescriptors + right.sortDescriptors) + } + + /** + Combines two `OrderBy` sort descriptors together and stores the result to the left operand + */ + public static func += (left: inout OrderBy, right: OrderBy) { + + left = left + right + } + /** The list of sort descriptors */ diff --git a/Sources/Fetching and Querying/Concrete Clauses/Where.swift b/Sources/Fetching and Querying/Concrete Clauses/Where.swift index 0d54b9c..60bbb50 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/Where.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/Where.swift @@ -27,22 +27,6 @@ import Foundation import CoreData -public func && (left: Where, right: Where) -> Where { - - return Where(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) -} - -public func || (left: Where, right: Where) -> Where { - - return Where(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) -} - -public prefix func ! (clause: Where) -> Where { - - return Where(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate])) -} - - // MARK: - Where /** @@ -50,6 +34,30 @@ public prefix func ! (clause: Where) -> Where { */ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable { + /** + Combines two `Where` predicates together using `AND` operator + */ + public static func && (left: Where, right: Where) -> Where { + + return Where(NSCompoundPredicate(type: .and, subpredicates: [left.predicate, right.predicate])) + } + + /** + Combines two `Where` predicates together using `OR` operator + */ + public static func || (left: Where, right: Where) -> Where { + + return Where(NSCompoundPredicate(type: .or, subpredicates: [left.predicate, right.predicate])) + } + + /** + Inverts the predicate of a `Where` clause using `NOT` operator + */ + public static prefix func ! (clause: Where) -> Where { + + return Where(NSCompoundPredicate(type: .not, subpredicates: [clause.predicate])) + } + /** The `NSPredicate` for the fetch or query */