mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-14 21:23:43 +01:00
added utilities for combining Where arrays and OrderBy arrays
This commit is contained in:
@@ -172,3 +172,17 @@ public struct OrderBy: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
return (self.sortDescriptors as NSArray).hashValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Sequence where Element == OrderBy
|
||||
|
||||
public extension Sequence where Iterator.Element == OrderBy {
|
||||
|
||||
/**
|
||||
Combines multiple `OrderBy` predicates together
|
||||
*/
|
||||
public func combined() -> OrderBy {
|
||||
|
||||
return OrderBy(self.flatMap({ $0.sortDescriptors }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,3 +216,25 @@ public struct Where: FetchClause, QueryClause, DeleteClause, Hashable {
|
||||
return self.predicate.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Sequence where Element == Where
|
||||
|
||||
public extension Sequence where Iterator.Element == Where {
|
||||
|
||||
/**
|
||||
Combines multiple `Where` predicates together using `AND` operator
|
||||
*/
|
||||
public func combinedByAnd() -> Where {
|
||||
|
||||
return Where(NSCompoundPredicate(type: .and, subpredicates: self.map({ $0.predicate })))
|
||||
}
|
||||
|
||||
/**
|
||||
Combines multiple `Where` predicates together using `OR` operator
|
||||
*/
|
||||
public func combinedByOr() -> Where {
|
||||
|
||||
return Where(NSCompoundPredicate(type: .or, subpredicates: self.map({ $0.predicate })))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user