No more #if swift(>=4.1)

This commit is contained in:
Gwendal Roué committed 2018-04-30 08:26:23 +02:00
1 parent e05a64f1cb
commit 5747d1cff0
16 files changed
+3 -165

No files matched your search

-8
View File
@@ -481,9 +481,6 @@
56B021CD1D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */; };
56B14E831D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */; };
56B15D0B1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */; };
56B1C3CD201C8D0E001938DA /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B1C3CC201C8D0E001938DA /* Swift4.1.swift */; };
56B1C3CE201C8D0E001938DA /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B1C3CC201C8D0E001938DA /* Swift4.1.swift */; };
56B1C3CF201C8D0E001938DA /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B1C3CC201C8D0E001938DA /* Swift4.1.swift */; };
56B6EF56208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */; };
56B6EF57208CB4E3002F0ACB /* ColumnExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */; };
56B7F42A1BE14A1900E39BBF /* CGFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */; };
@@ -1030,7 +1027,6 @@
56B021C81D8C0D3900B239BB /* MutablePersistableRecordPersistenceConflictPolicyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutablePersistableRecordPersistenceConflictPolicyTests.swift; sourceTree = "<group>"; };
56B14E7E1D4DAE54000BF4A3 /* RowFromDictionaryLiteralTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowFromDictionaryLiteralTests.swift; sourceTree = "<group>"; };
56B15D0A1CD4C35100A24C8B /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsControllerTests.swift; sourceTree = "<group>"; };
56B1C3CC201C8D0E001938DA /* Swift4.1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
56B6EF55208CB4E3002F0ACB /* ColumnExpressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColumnExpressionTests.swift; sourceTree = "<group>"; };
56B7F4291BE14A1900E39BBF /* CGFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloatTests.swift; sourceTree = "<group>"; };
56B7F4391BEB42D500E39BBF /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = "<group>"; };
@@ -1748,7 +1744,6 @@
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
569A98EC2039B6F3008D7DBF /* Fixits-3.0.swift */,
56B1C3CC201C8D0E001938DA /* Swift4.1.swift */,
);
path = Legacy;
sourceTree = "<group>";
@@ -2399,7 +2394,6 @@
5653EB1720944C7C00F46237 /* AssociationQuery.swift in Sources */,
565490B81D5AE236005622CB /* DatabaseError.swift in Sources */,
56BF6D3C1DEF47DA006039A3 /* Fixits-0-90-1.swift in Sources */,
56B1C3CF201C8D0E001938DA /* Swift4.1.swift in Sources */,
56DAA2E11DE9C827006E10C8 /* Cursor.swift in Sources */,
5653EB0520944C7C00F46237 /* BelongsToAssociation.swift in Sources */,
565490BC1D5AE236005622CB /* DatabaseSchemaCache.swift in Sources */,
@@ -2487,7 +2481,6 @@
5674A7081F307FCD0095F066 /* DatabaseValueConvertible+ReferenceConvertible.swift in Sources */,
56A2388C1B9C75030082EB20 /* Statement.swift in Sources */,
5659F4931EA8D964004A4992 /* ReadWriteBox.swift in Sources */,
56B1C3CE201C8D0E001938DA /* Swift4.1.swift in Sources */,
5605F1941C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */,
56B7F43B1BEB42D500E39BBF /* Migration.swift in Sources */,
5690C3431D23E82A00E59934 /* Data.swift in Sources */,
@@ -2928,7 +2921,6 @@
5605F1931C6B1A8700235C62 /* QueryInterfaceQuery.swift in Sources */,
566B912B1FA4D0CC0012D5B0 /* StatementAuthorizer.swift in Sources */,
56A2388B1B9C75030082EB20 /* Statement.swift in Sources */,
56B1C3CD201C8D0E001938DA /* Swift4.1.swift in Sources */,
5690C3401D23E82A00E59934 /* Data.swift in Sources */,
5659F4881EA8D94E004A4992 /* Utils.swift in Sources */,
56FC98781D969DEF00E3C842 /* SQLExpression+QueryInterface.swift in Sources */,
-8
View File
@@ -132,7 +132,6 @@ extension Cursor {
return nil
}
#if swift(>=4.1)
/// Returns a cursor over the concatenated non-nil results of mapping
/// transform over this cursor.
public func compactMap<ElementOfResult>(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor<FilterCursor<MapCursor<Self, ElementOfResult?>>, ElementOfResult> {
@@ -143,13 +142,6 @@ extension Cursor {
public func flatMap<ElementOfResult>(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor<FilterCursor<MapCursor<Self, ElementOfResult?>>, ElementOfResult> {
return compactMap(transform)
}
#else
/// Returns a cursor over the concatenated non-nil results of mapping
/// transform over this cursor.
public func flatMap<ElementOfResult>(_ transform: @escaping (Element) throws -> ElementOfResult?) -> MapCursor<FilterCursor<MapCursor<Self, ElementOfResult?>>, ElementOfResult> {
return map(transform).filter { $0 != nil }.map { $0! }
}
#endif
/// Returns a cursor that skips any initial elements that satisfy
/// `predicate`.
-16
View File
@@ -867,14 +867,6 @@ extension Database {
self.rawValue = rawValue
}
#if !swift(>=4.1)
/// The hash value
/// :nodoc:
public var hashValue: Int {
return rawValue.hashValue
}
#endif
/// The `BINARY` built-in SQL collation
public static let binary = CollationName("BINARY")
@@ -906,14 +898,6 @@ extension Database {
self.rawValue = rawValue
}
#if !swift(>=4.1)
/// The hash value
/// :nodoc:
public var hashValue: Int {
return rawValue.hashValue
}
#endif
/// The `TEXT` SQL column type
public static let text = ColumnType("TEXT")
-10
View File
@@ -139,16 +139,6 @@ public struct ResultCode : RawRepresentable, Equatable, CustomStringConvertible
public static let SQLITE_OK_LOAD_PERMANENTLY = ResultCode(rawValue: (SQLITE_OK.rawValue | (1<<8)))
}
#if !swift(>=4.1)
// Equatable
extension ResultCode {
/// :nodoc:
public static func == (_ lhs: ResultCode, _ rhs: ResultCode) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
#endif
// CustomStringConvertible
extension ResultCode {
/// :nodoc:
-10
View File
@@ -10,16 +10,6 @@ public final class DatabaseFunction: Hashable {
private struct Identity: Hashable {
let name: String
let nArg: Int32 // -1 for variadic functions
#if !swift(>=4.1)
var hashValue: Int {
return name.hashValue ^ nArg.hashValue
}
static func == (lhs: Identity, rhs: Identity) -> Bool {
return lhs.name == rhs.name && lhs.nArg == rhs.nArg
}
#endif
}
public var name: String { return identity.name }
-8
View File
@@ -255,14 +255,6 @@ private struct TableRegion: Equatable {
return false
}
#if !swift(>=4.1)
static func == (lhs: TableRegion, rhs: TableRegion) -> Bool {
if lhs.columns != rhs.columns { return false }
if lhs.rowIds != rhs.rowIds { return false }
return true
}
#endif
func intersection(_ other: TableRegion) -> TableRegion {
let columnsIntersection: Set<String>?
switch (self.columns, other.columns) {
-12
View File
@@ -905,18 +905,6 @@ extension StatementArguments {
}
}
#if !swift(>=4.1)
// Equatable
extension StatementArguments {
/// :nodoc:
public static func == (lhs: StatementArguments, rhs: StatementArguments) -> Bool {
if lhs.values != rhs.values { return false }
if lhs.namedValues != rhs.namedValues { return false }
return true
}
}
#endif
/// A thread-unsafe statement cache
struct StatementCache {
unowned let db: Database
-24
View File
@@ -1,24 +0,0 @@
// Compatibility layer for Swift < 4.1
#if !swift(>=4.1)
extension Sequence {
// From future import SE-0187
func compactMap<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] {
return try flatMap(transform)
}
}
extension UnsafeMutablePointer {
// From future import SE-0184
func deallocate() {
deallocate(capacity: 0)
}
}
extension UnsafeMutableRawBufferPointer {
// From future import SE-0184
func copyMemory<C>(from source: C) where C : Collection, C.Element == UInt8 {
copyBytes(from: source)
}
}
#endif
@@ -556,7 +556,7 @@ public struct SQLFunctionName : Hashable {
/// The SQL function name
///
/// :nodoc:
public let sql: String
public var sql: String
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
///
@@ -568,22 +568,6 @@ public struct SQLFunctionName : Hashable {
public init(_ sql: String) {
self.sql = sql
}
#if !swift(>=4.1)
/// The hash value
///
/// :nodoc:
public var hashValue: Int {
return sql.hashValue
}
/// Equality operator
///
/// :nodoc:
public static func == (lhs: SQLFunctionName, rhs: SQLFunctionName) -> Bool {
return lhs.sql == rhs.sql
}
#endif
}
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
+2 -19
View File
@@ -991,16 +991,8 @@ private struct InsertQuery: Hashable {
let tableName: String
let insertedColumns: [String]
// Not generated by Swift 4.1
// TODO: remove when Swift can generate it
var hashValue: Int { return tableName.hashValue }
#if !swift(>=4.1)
static func == (lhs: InsertQuery, rhs: InsertQuery) -> Bool {
if lhs.tableName != rhs.tableName { return false }
if lhs.onConflict != rhs.onConflict { return false }
return lhs.insertedColumns == rhs.insertedColumns
}
#endif
}
extension InsertQuery {
@@ -1032,17 +1024,8 @@ private struct UpdateQuery: Hashable {
let updatedColumns: [String]
let conditionColumns: [String]
// Not generated by Swift 4.1
// TODO: remove when Swift can generate it
var hashValue: Int { return tableName.hashValue }
#if !swift(>=4.1)
static func == (lhs: UpdateQuery, rhs: UpdateQuery) -> Bool {
if lhs.tableName != rhs.tableName { return false }
if lhs.onConflict != rhs.onConflict { return false }
if lhs.updatedColumns != rhs.updatedColumns { return false }
return lhs.conditionColumns == rhs.conditionColumns
}
#endif
}
extension UpdateQuery {
-6
View File
@@ -554,8 +554,6 @@
5698AD391DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
569A98FC2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; };
569A98FD2039B72D008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */; };
569B7FA8201C904C0069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA6201C904C0069DE70 /* Swift4.1.swift */; };
569B7FA9201C904C0069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA6201C904C0069DE70 /* Swift4.1.swift */; };
569C1EB31CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
569C1EB41CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
569C1EB61CF07DDD0042627B /* SchedulingWatchdogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */; };
@@ -1076,7 +1074,6 @@
5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = "<group>"; };
5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = "<group>"; };
569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = "<group>"; };
569B7FA6201C904C0069DE70 /* Swift4.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = "<group>"; };
569EF0E8200D387000A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = "<group>"; };
56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
@@ -1753,7 +1750,6 @@
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
569A98FA2039B72C008D7DBF /* Fixits-3.0.swift */,
569B7FA6201C904C0069DE70 /* Swift4.1.swift */,
);
path = Legacy;
sourceTree = "<group>";
@@ -2164,7 +2160,6 @@
564F9C2F1F07611400877A00 /* DatabaseFunction.swift in Sources */,
5659F4991EA8D989004A4992 /* Pool.swift in Sources */,
5653EB8F20961FC000F46237 /* BelongsToAssociation.swift in Sources */,
569B7FA8201C904C0069DE70 /* Swift4.1.swift in Sources */,
5674A6FA1F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB54D1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5664759B1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
@@ -2597,7 +2592,6 @@
564F9C321F07611700877A00 /* DatabaseFunction.swift in Sources */,
5659F49C1EA8D989004A4992 /* Pool.swift in Sources */,
5653EB9020961FC000F46237 /* BelongsToAssociation.swift in Sources */,
569B7FA9201C904C0069DE70 /* Swift4.1.swift in Sources */,
5674A6F71F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB5501EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5664759E1D97D8A000FF74B8 /* SQLCollection.swift in Sources */,
-6
View File
@@ -237,8 +237,6 @@
5698AD3A1DABAF4A0056AF8C /* FTS5CustomTokenizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */; };
569A98F82039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; };
569A98F92039B716008D7DBF /* Fixits-3.0.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569A98F62039B716008D7DBF /* Fixits-3.0.swift */; };
569B7FA4201C90430069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA2201C90430069DE70 /* Swift4.1.swift */; };
569B7FA5201C90430069DE70 /* Swift4.1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569B7FA2201C90430069DE70 /* Swift4.1.swift */; };
569EF0E6200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */; };
569EF0E7200D37FD00A9FA45 /* DatabaseRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */; };
56A4CDB31D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A4CDAF1D4234B200B1A9B9 /* SQLExpressionLiteralTests.swift */; };
@@ -743,7 +741,6 @@
5698AD201DABAEFA0056AF8C /* FTS5WrapperTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5WrapperTokenizer.swift; sourceTree = "<group>"; };
5698AD341DABAF4A0056AF8C /* FTS5CustomTokenizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FTS5CustomTokenizer.swift; sourceTree = "<group>"; };
569A98F62039B716008D7DBF /* Fixits-3.0.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Fixits-3.0.swift"; sourceTree = "<group>"; };
569B7FA2201C90430069DE70 /* Swift4.1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swift4.1.swift; sourceTree = "<group>"; };
569C1EB11CF07DDD0042627B /* SchedulingWatchdogTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SchedulingWatchdogTests.swift; sourceTree = "<group>"; };
569EF0E5200D37FC00A9FA45 /* DatabaseRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseRegion.swift; sourceTree = "<group>"; };
56A238131B9C74A90082EB20 /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
@@ -1399,7 +1396,6 @@
56D121591ED34978001347D2 /* Fixits-0.109.0.swift */,
56873BEB1F2CB400004D24B4 /* Fixits-1.2.swift */,
569A98F62039B716008D7DBF /* Fixits-3.0.swift */,
569B7FA2201C90430069DE70 /* Swift4.1.swift */,
);
path = Legacy;
sourceTree = "<group>";
@@ -1839,7 +1835,6 @@
564F9C331F07611800877A00 /* DatabaseFunction.swift in Sources */,
5659F49D1EA8D989004A4992 /* Pool.swift in Sources */,
5653EB4220961F6100F46237 /* BelongsToAssociation.swift in Sources */,
569B7FA5201C90430069DE70 /* Swift4.1.swift in Sources */,
5674A6F61F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB5511EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5698AC3C1D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
@@ -2111,7 +2106,6 @@
564F9C301F07611500877A00 /* DatabaseFunction.swift in Sources */,
5659F49A1EA8D989004A4992 /* Pool.swift in Sources */,
5653EB4120961F6100F46237 /* BelongsToAssociation.swift in Sources */,
569B7FA4201C90430069DE70 /* Swift4.1.swift in Sources */,
5674A6F51F307F600095F066 /* PersistableRecord+Encodable.swift in Sources */,
56CEB54E1EAA359A00BFAF62 /* SQLExpressible.swift in Sources */,
5698AC391D9E5A590056AF8C /* FTS3Pattern.swift in Sources */,
-9
View File
@@ -78,21 +78,12 @@ class CursorTests: GRDBTestCase {
}
}
#if swift(>=4.1)
func testCompactMap() {
let cursor = AnyCursor(["1", "foo", "2"]).compactMap { Int($0) }
XCTAssertEqual(try cursor.next()!, 1)
XCTAssertEqual(try cursor.next()!, 2)
XCTAssertTrue(try cursor.next() == nil) // end
}
#else
func testFlatMapOfOptional() {
let cursor = AnyCursor(["1", "foo", "2"]).flatMap { Int($0) }
XCTAssertEqual(try cursor.next()!, 1)
XCTAssertEqual(try cursor.next()!, 2)
XCTAssertTrue(try cursor.next() == nil) // end
}
#endif
func testForEach() throws {
let cursor = AnyCursor([1, 2])
@@ -295,11 +295,7 @@ class DatabaseAggregateTests: GRDBTestCase {
struct Aggregate : DatabaseAggregate {
var result: DatabaseValueConvertible?
mutating func step(_ dbValues: [DatabaseValue]) {
#if swift(>=4.1)
let ints = dbValues.compactMap { Int.fromDatabaseValue($0) }
#else
let ints = dbValues.flatMap { Int.fromDatabaseValue($0) }
#endif
result = ints.reduce(0, +)
}
func finalize() -> DatabaseValueConvertible? {
@@ -250,11 +250,7 @@ class DatabaseFunctionTests: GRDBTestCase {
func testFunctionOfTwoArguments() throws {
let dbQueue = try makeDatabaseQueue()
let fn = DatabaseFunction("f", argumentCount: 2) { dbValues in
#if swift(>=4.1)
let ints = dbValues.compactMap { Int.fromDatabaseValue($0) }
#else
let ints = dbValues.flatMap { Int.fromDatabaseValue($0) }
#endif
return ints.reduce(0, +)
}
dbQueue.add(function: fn)
@@ -31,11 +31,7 @@ class QueryInterfaceExpressionsTests: GRDBTestCase {
dbWriter.add(collation: collation)
customFunction = DatabaseFunction("avgOf", pure: true) { dbValues in
#if swift(>=4.1)
let sum = dbValues.compactMap { Int.fromDatabaseValue($0) }.reduce(0, +)
#else
let sum = dbValues.flatMap { Int.fromDatabaseValue($0) }.reduce(0, +)
#endif
return Double(sum) / Double(dbValues.count)
}
dbWriter.add(function: self.customFunction)