@@ -12,6 +12,38 @@ import Foundation
1212// swiftlint:disable file_length
1313
1414extension CoreDataRepository {
15+ public enum AggregateFunction : String {
16+ case count
17+ case sum
18+ case average
19+ case min
20+ case max
21+ }
22+
23+ @inlinable
24+ public func aggregate< Value: Numeric > (
25+ function: AggregateFunction ,
26+ predicate: NSPredicate ,
27+ entityDesc: NSEntityDescription ,
28+ attributeDesc: NSAttributeDescription ,
29+ groupBy: NSAttributeDescription ? = nil ,
30+ as valueType: Value . Type
31+ ) async -> Result < Value , CoreDataError > {
32+ switch function {
33+ case . count:
34+ return await count ( predicate: predicate, entityDesc: entityDesc, as: valueType)
35+ default :
36+ return await Self . send (
37+ function: . sum,
38+ context: context,
39+ predicate: predicate,
40+ entityDesc: entityDesc,
41+ attributeDesc: attributeDesc,
42+ groupBy: groupBy
43+ )
44+ }
45+ }
46+
1547 // MARK: Count
1648
1749 /// Get the count or quantity of managed object instances that satisfy the predicate.
@@ -375,15 +407,6 @@ extension CoreDataRepository {
375407
376408 // MARK: Internals
377409
378- @usableFromInline
379- enum AggregateFunction : String {
380- case count
381- case sum
382- case average
383- case min
384- case max
385- }
386-
387410 private static func aggregate< Value: Numeric > (
388411 context: NSManagedObjectContext ,
389412 request: NSFetchRequest < NSDictionary >
0 commit comments