From 10c9e75f812ab3296c18ab0a05f6cbc957fc1565 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Wed, 8 Jan 2020 21:07:59 +0100 Subject: [PATCH 01/10] New mapValues, compactMapValues and filterValues --- Sources/Guarantee.swift | 55 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Sources/Guarantee.swift b/Sources/Guarantee.swift index d032f9b7e..9297e1e58 100644 --- a/Sources/Guarantee.swift +++ b/Sources/Guarantee.swift @@ -117,7 +117,7 @@ public extension Guarantee { } #endif - @discardableResult + @discardableResult func then(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ body: @escaping(T) -> Guarantee) -> Guarantee { let rg = Guarantee(.pending) pipe { value in @@ -169,6 +169,21 @@ public extension Guarantee where T: Sequence { return map(on: on, flags: flags) { $0.map(transform) } } + #if swift(>=4) + /** + `Guarantee<[T]>` => `KeyPath` => `Guarantee<[U]>` + + Guarantee.value([Person(name: "Max"), Person(name: "Roman"), Person(name: "John")]) + .mapValues(\.name) + .done { + // $0 => ["Max", "Roman", "John"] + } + */ + func mapValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Guarantee<[U]> { + return map(on: on, flags: flags) { $0.map { $0[keyPath: keyPath] } } + } + #endif + /** `Guarantee<[T]>` => `T` -> `[U]` => `Guarantee<[U]>` @@ -203,6 +218,27 @@ public extension Guarantee where T: Sequence { } } + #if swift(>=4) + /** + `Guarantee<[T]>` => `KeyPath` => `Guarantee<[U]>` + + Guarantee.value([Person(name: "Max"), Person(name: "Roman", age: 26), Person(name: "John", age: 23)]) + .compactMapValues(\.age) + .done { + // $0 => [26, 23] + } + */ + func compactMapValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Guarantee<[U]> { + return map(on: on, flags: flags) { foo -> [U] in + #if !swift(>=4.1) + return foo.flatMap { $0[keyPath: keyPath] } + #else + return foo.compactMap { $0[keyPath: keyPath] } + #endif + } + } + #endif + /** `Guarantee<[T]>` => `T` -> `Guarantee` => `Guaranetee<[U]>` @@ -256,6 +292,23 @@ public extension Guarantee where T: Sequence { } } + #if swift(>=4) + /** + `Guarantee<[T]>` => `KeyPath` => `Guarantee<[T]>` + + Guarantee.value([Person(name: "Max"), Person(name: "Roman", age: 26, isStudent: false), Person(name: "John", age: 23, isStudent: true)]) + .filterValues(\.isStudent) + .done { + // $0 => [Person(name: "John", age: 23, isStudent: true)] + } + */ + func filterValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Guarantee<[T.Iterator.Element]> { + return map(on: on, flags: flags) { + $0.filter { $0[keyPath: keyPath] } + } + } + #endif + /** `Guarantee<[T]>` => (`T`, `T`) -> Bool => `Guarantee<[T]>` From 5fb0714f47210b88cdaaa0cb6b42fa0f7358facf Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Wed, 8 Jan 2020 21:10:42 +0100 Subject: [PATCH 02/10] New compactMap, mapValues, compactMapValues, filterValues --- Sources/Thenable.swift | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/Sources/Thenable.swift b/Sources/Thenable.swift index 62cc1c179..56196ff49 100644 --- a/Sources/Thenable.swift +++ b/Sources/Thenable.swift @@ -149,6 +149,38 @@ public extension Thenable { return rp } + #if swift(>=4) + /** + Similar to func `compactMap(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping(T) throws -> U?) -> Promise`, but accepts a key path instead of a closure. + + - Parameter on: The queue to which the provided key path for value dispatches. + - Parameter keyPath: The key path to the value that is using when this Promise is fulfilled. If the value for `keyPath` is `nil` the resulting promise is rejected with `PMKError.compactMap`. + - Returns: A new promise that is fulfilled with the value for the provided key path. + */ + func compactMap(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Promise { + let rp = Promise(.pending) + pipe { + switch $0 { + case .fulfilled(let value): + on.async(flags: flags) { + do { + if let rv = value[keyPath: keyPath] { + rp.box.seal(.fulfilled(rv)) + } else { + throw PMKError.compactMap(value, U.self) + } + } catch { + rp.box.seal(.rejected(error)) + } + } + case .rejected(let error): + rp.box.seal(.rejected(error)) + } + } + return rp + } + #endif + /** The provided closure is executed when this promise is fulfilled. @@ -314,6 +346,21 @@ public extension Thenable where T: Sequence { return map(on: on, flags: flags){ try $0.map(transform) } } + #if swift(>=4) + /** + `Promise<[T]>` => `KeyPath` => `Promise<[U]>` + + firstly { + .value([Person(name: "Max"), Person(name: "Roman"), Person(name: "John")]) + }.mapValues(\.name).done { + // $0 => ["Max", "Roman", "John"] + } + */ + func mapValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Promise<[U]> { + return map(on: on, flags: flags){ $0.map { $0[keyPath: keyPath] } } + } + #endif + /** `Promise<[T]>` => `T` -> `[U]` => `Promise<[U]>` @@ -352,6 +399,27 @@ public extension Thenable where T: Sequence { } } + #if swift(>=4) + /** + `Promise<[T]>` => `KeyPath` => `Promise<[U]>` + + firstly { + .value([Person(name: "Max"), Person(name: "Roman", age: 26), Person(name: "John", age: 23)]) + }.compactMapValues(\.age).done { + // $0 => [26, 23] + } + */ + func compactMapValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Promise<[U]> { + return map(on: on, flags: flags) { foo -> [U] in + #if !swift(>=4.1) + return foo.flatMap { $0[keyPath: keyPath] } + #else + return foo.compactMap { $0[keyPath: keyPath] } + #endif + } + } + #endif + /** `Promise<[T]>` => `T` -> `Promise` => `Promise<[U]>` @@ -404,6 +472,23 @@ public extension Thenable where T: Sequence { $0.filter(isIncluded) } } + + #if swift(>=4) + /** + `Promise<[T]>` => `KeyPath` => `Promise<[T]>` + + firstly { + .value([Person(name: "Max"), Person(name: "Roman", age: 26, isStudent: false), Person(name: "John", age: 23, isStudent: true)]) + }.filterValues(\.isStudent).done { + // $0 => [Person(name: "John", age: 23, isStudent: true)] + } + */ + func filterValues(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Promise<[T.Iterator.Element]> { + return map(on: on, flags: flags) { + $0.filter { $0[keyPath: keyPath] } + } + } + #endif } public extension Thenable where T: Collection { From 35379bb8a0cb5cdaaa0c59681b0e59c7d9cf8d40 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Wed, 8 Jan 2020 21:12:41 +0100 Subject: [PATCH 03/10] struct Person and tests for new mapping functions --- Tests/CorePromise/ThenableTests.swift | 86 ++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/Tests/CorePromise/ThenableTests.swift b/Tests/CorePromise/ThenableTests.swift index 485833cbd..4063a87f6 100644 --- a/Tests/CorePromise/ThenableTests.swift +++ b/Tests/CorePromise/ThenableTests.swift @@ -2,6 +2,22 @@ import PromiseKit import Dispatch import XCTest +struct Person: Equatable { + let name: String + let age: Int? + let isStudent: Bool + + init( + name: String = "", + age: Int? = nil, + isStudent: Bool = false + ) { + self.name = name + self.age = age + self.isStudent = isStudent + } +} + class ThenableTests: XCTestCase { func testGet() { let ex1 = expectation(description: "") @@ -30,8 +46,8 @@ class ThenableTests: XCTestCase { #if swift(>=4) func testMapByKeyPath() { let ex = expectation(description: "") - Promise.value("Hello world").map(\.count).done { - XCTAssertEqual($0, 11) + Promise.value(Person(name: "Max")).map(\.name).done { + XCTAssertEqual($0, "Max") ex.fulfill() }.silenceWarning() wait(for: [ex], timeout: 10) @@ -94,6 +110,39 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } + #if swift(>=4) + func testCompactMapByKeyPath() { + let ex = expectation(description: "") + Promise.value(Person(name: "Roman", age: 26)).compactMap(\.age).done { + XCTAssertEqual($0, 26) + ex.fulfill() + }.silenceWarning() + wait(for: [ex], timeout: 10) + } + #endif + + func testMapValues() { + let ex = expectation(description: "") + Promise.value([14, 20, 45]).mapValues { + $0 * 2 + }.done { + XCTAssertEqual([28, 40, 90], $0) + ex.fulfill() + }.silenceWarning() + wait(for: [ex], timeout: 10) + } + + #if swift(>=4) + func testMapValuesByKeyPath() { + let ex = expectation(description: "") + Promise.value([Person(name: "Max"), Person(name: "Roman"), Person(name: "John")]).mapValues(\.name).done { + XCTAssertEqual(["Max", "Roman", "John"], $0) + ex.fulfill() + }.silenceWarning() + wait(for: [ex], timeout: 10) + } + #endif + func testCompactMapValues() { let ex = expectation(description: "") Promise.value(["1","2","a","4"]).compactMapValues { @@ -105,6 +154,17 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } + #if swift(>=4) + func testCompactMapValuesByKeyPath() { + let ex = expectation(description: "") + Promise.value([Person(name: "Max"), Person(name: "Roman", age: 26), Person(name: "John", age: 23)]).compactMapValues(\.age).done { + XCTAssertEqual([26, 23], $0) + ex.fulfill() + }.silenceWarning() + wait(for: [ex], timeout: 10) + } + #endif + func testThenMap() { let ex = expectation(description: "") Promise.value([1,2,3,4]).thenMap { @@ -127,6 +187,28 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } + func testFilterValues() { + let ex = expectation(description: "") + Promise.value([Person(name: "Max"), Person(name: "Roman", age: 26, isStudent: false), Person(name: "John", age: 23, isStudent: true)]).filterValues { + $0.isStudent + }.done { + XCTAssertEqual([Person(name: "John", age: 23, isStudent: true)], $0) + ex.fulfill() + }.silenceWarning() + wait(for: [ex], timeout: 10) + } + + #if swift(>=4) + func testFilterValuesByKeyPath() { + let ex = expectation(description: "") + Promise.value([Person(name: "Max"), Person(name: "Roman", age: 26, isStudent: false), Person(name: "John", age: 23, isStudent: true)]).filterValues(\.isStudent).done { + XCTAssertEqual([Person(name: "John", age: 23, isStudent: true)], $0) + ex.fulfill() + }.silenceWarning() + wait(for: [ex], timeout: 10) + } + #endif + func testLastValueForEmpty() { XCTAssertTrue(Promise.value([]).lastValue.isRejected) } From 15a73f95cd4ea93f3a74b046ffc419702efe9cfa Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Wed, 8 Jan 2020 21:15:05 +0100 Subject: [PATCH 04/10] Tests for new mapping functions --- Tests/CorePromise/GuaranteeTests.swift | 50 ++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/Tests/CorePromise/GuaranteeTests.swift b/Tests/CorePromise/GuaranteeTests.swift index 33e02e636..c492c35df 100644 --- a/Tests/CorePromise/GuaranteeTests.swift +++ b/Tests/CorePromise/GuaranteeTests.swift @@ -30,8 +30,8 @@ class GuaranteeTests: XCTestCase { func testMapByKeyPath() { let ex = expectation(description: "") - Guarantee.value("Hello world").map(\.count).done { - XCTAssertEqual(11, $0) + Guarantee.value(Person(name: "Max")).map(\.name).done { + XCTAssertEqual("Max", $0) ex.fulfill() } @@ -56,6 +56,21 @@ class GuaranteeTests: XCTestCase { wait(for: [ex], timeout: 10) } + #if swift(>=4) + func testMapValuesByKeyPath() { + let ex = expectation(description: "") + + Guarantee.value([Person(name: "Max"), Person(name: "Roman"), Person(name: "John")]) + .mapValues(\.name) + .done { values in + XCTAssertEqual(["Max", "Roman", "John"], values) + ex.fulfill() + } + + wait(for: [ex], timeout: 10) + } + #endif + func testFlatMapValues() { let ex = expectation(description: "") @@ -82,6 +97,21 @@ class GuaranteeTests: XCTestCase { wait(for: [ex], timeout: 10) } + #if swift(>=4) + func testCompactMapValuesByKeyPath() { + let ex = expectation(description: "") + + Guarantee.value([Person(name: "Max"), Person(name: "Roman", age: 26), Person(name: "John", age: 23)]) + .compactMapValues(\.age) + .done { values in + XCTAssertEqual([26, 23], values) + ex.fulfill() + } + + wait(for: [ex], timeout: 10) + } + #endif + func testThenMap() { let ex = expectation(description: "") @@ -124,6 +154,22 @@ class GuaranteeTests: XCTestCase { wait(for: [ex], timeout: 10) } + #if swift(>=4) + func testFilterValuesByKeyPath() { + + let ex = expectation(description: "") + + Guarantee.value([Person(name: "Max"), Person(name: "Roman", age: 26, isStudent: false), Person(name: "John", age: 23, isStudent: true)]) + .filterValues(\.isStudent) + .done { values in + XCTAssertEqual([Person(name: "John", age: 23, isStudent: true)], values) + ex.fulfill() + } + + wait(for: [ex], timeout: 10) + } + #endif + func testSorted() { let ex = expectation(description: "") From bf293b7395441c345042fd6590ec6e7460646650 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Wed, 8 Jan 2020 21:17:06 +0100 Subject: [PATCH 05/10] New items in GuaranteeTests and ThenableTests --- Tests/CorePromise/XCTestManifests.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tests/CorePromise/XCTestManifests.swift b/Tests/CorePromise/XCTestManifests.swift index 4d0824cdc..9521070cd 100644 --- a/Tests/CorePromise/XCTestManifests.swift +++ b/Tests/CorePromise/XCTestManifests.swift @@ -56,12 +56,15 @@ extension GuaranteeTests { // to regenerate. static let __allTests__GuaranteeTests = [ ("testCompactMapValues", testCompactMapValues), + ("testCompactMapValuesByKeyPath", testCompactMapValuesByKeyPath), ("testFilterValues", testFilterValues), + ("testFilterValuesByKeyPath", testFilterValuesByKeyPath), ("testFlatMapValues", testFlatMapValues), ("testInit", testInit), ("testMap", testMap), ("testMapByKeyPath", testMapByKeyPath), ("testMapValues", testMapValues), + ("testMapValuesByKeyPath", testMapValuesByKeyPath), ("testNoAmbiguityForValue", testNoAmbiguityForValue), ("testSorted", testSorted), ("testSortedBy", testSortedBy), @@ -190,13 +193,19 @@ extension ThenableTests { ("testCompactMap", testCompactMap), ("testCompactMapThrows", testCompactMapThrows), ("testCompactMapValues", testCompactMapValues), + ("testCompactMapValuesByKeyPath", testCompactMapValuesByKeyPath), ("testDispatchFlagsSyntax", testDispatchFlagsSyntax), ("testFirstValueForEmpty", testFirstValueForEmpty), ("testGet", testGet), + ("testFilterValues", testFilterValues), + ("testFilterValuesByKeyPath", testFilterValuesByKeyPath), ("testLastValueForEmpty", testLastValueForEmpty), ("testMap", testMap), ("testMapByKeyPath", testMapByKeyPath), ("testPMKErrorCompactMap", testPMKErrorCompactMap), + ("testCompactMapByKeyPath", testCompactMapByKeyPath), + ("testMapValues", testMapValues), + ("testMapValuesByKeyPath", testMapValuesByKeyPath), ("testRejectedPromiseCompactMap", testRejectedPromiseCompactMap), ("testThenFlatMap", testThenFlatMap), ("testThenMap", testThenMap), From 9ea7d3daed60d0d69e70469962d3e5c5ff534fb2 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Wed, 8 Jan 2020 22:26:55 +0100 Subject: [PATCH 06/10] Fixed tests ordering --- Tests/CorePromise/XCTestManifests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/CorePromise/XCTestManifests.swift b/Tests/CorePromise/XCTestManifests.swift index 9521070cd..9fbe50243 100644 --- a/Tests/CorePromise/XCTestManifests.swift +++ b/Tests/CorePromise/XCTestManifests.swift @@ -191,21 +191,21 @@ extension ThenableTests { static let __allTests__ThenableTests = [ ("testBarrier", testBarrier), ("testCompactMap", testCompactMap), + ("testCompactMapByKeyPath", testCompactMapByKeyPath), ("testCompactMapThrows", testCompactMapThrows), ("testCompactMapValues", testCompactMapValues), ("testCompactMapValuesByKeyPath", testCompactMapValuesByKeyPath), ("testDispatchFlagsSyntax", testDispatchFlagsSyntax), - ("testFirstValueForEmpty", testFirstValueForEmpty), - ("testGet", testGet), ("testFilterValues", testFilterValues), ("testFilterValuesByKeyPath", testFilterValuesByKeyPath), + ("testFirstValueForEmpty", testFirstValueForEmpty), + ("testGet", testGet), ("testLastValueForEmpty", testLastValueForEmpty), ("testMap", testMap), ("testMapByKeyPath", testMapByKeyPath), - ("testPMKErrorCompactMap", testPMKErrorCompactMap), - ("testCompactMapByKeyPath", testCompactMapByKeyPath), ("testMapValues", testMapValues), ("testMapValuesByKeyPath", testMapValuesByKeyPath), + ("testPMKErrorCompactMap", testPMKErrorCompactMap), ("testRejectedPromiseCompactMap", testRejectedPromiseCompactMap), ("testThenFlatMap", testThenFlatMap), ("testThenMap", testThenMap), From 6652ad3d077a622d3fd779de0c70aba2ef8d51ba Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Tue, 14 Jan 2020 21:59:42 +0100 Subject: [PATCH 07/10] Functions that are using KeyPath require !swift(>=5.2) (Guarantee) --- Sources/Guarantee.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Guarantee.swift b/Sources/Guarantee.swift index 9297e1e58..ce887cdc3 100644 --- a/Sources/Guarantee.swift +++ b/Sources/Guarantee.swift @@ -105,7 +105,7 @@ public extension Guarantee { return rg } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func map(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ keyPath: KeyPath) -> Guarantee { let rg = Guarantee(.pending) pipe { value in @@ -169,7 +169,7 @@ public extension Guarantee where T: Sequence { return map(on: on, flags: flags) { $0.map(transform) } } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** `Guarantee<[T]>` => `KeyPath` => `Guarantee<[U]>` @@ -218,7 +218,7 @@ public extension Guarantee where T: Sequence { } } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** `Guarantee<[T]>` => `KeyPath` => `Guarantee<[U]>` @@ -292,7 +292,7 @@ public extension Guarantee where T: Sequence { } } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** `Guarantee<[T]>` => `KeyPath` => `Guarantee<[T]>` From 8fd461350fc2aa80d5d16d583094fab3ea310581 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Tue, 14 Jan 2020 22:01:01 +0100 Subject: [PATCH 08/10] Functions that are using KeyPath require !swift(>=5.2) (Thenable) --- Sources/Thenable.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Thenable.swift b/Sources/Thenable.swift index 56196ff49..a44e606c7 100644 --- a/Sources/Thenable.swift +++ b/Sources/Thenable.swift @@ -87,7 +87,7 @@ public extension Thenable { return rp } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** Similar to func `map(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping(T) throws -> U) -> Promise`, but accepts a key path instead of a closure. @@ -149,7 +149,7 @@ public extension Thenable { return rp } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** Similar to func `compactMap(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, _ transform: @escaping(T) throws -> U?) -> Promise`, but accepts a key path instead of a closure. @@ -346,7 +346,7 @@ public extension Thenable where T: Sequence { return map(on: on, flags: flags){ try $0.map(transform) } } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** `Promise<[T]>` => `KeyPath` => `Promise<[U]>` @@ -399,7 +399,7 @@ public extension Thenable where T: Sequence { } } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** `Promise<[T]>` => `KeyPath` => `Promise<[U]>` @@ -473,7 +473,7 @@ public extension Thenable where T: Sequence { } } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) /** `Promise<[T]>` => `KeyPath` => `Promise<[T]>` From 98e3f1cd28c05815ad0cdf80c48280f481f78b0b Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Tue, 14 Jan 2020 22:02:07 +0100 Subject: [PATCH 09/10] Tests for the functions that are using KeyPath require !swift(>=5.2) (Guarantee) --- Tests/CorePromise/GuaranteeTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/CorePromise/GuaranteeTests.swift b/Tests/CorePromise/GuaranteeTests.swift index c492c35df..9ee2f2847 100644 --- a/Tests/CorePromise/GuaranteeTests.swift +++ b/Tests/CorePromise/GuaranteeTests.swift @@ -26,7 +26,7 @@ class GuaranteeTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testMapByKeyPath() { let ex = expectation(description: "") @@ -56,7 +56,7 @@ class GuaranteeTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testMapValuesByKeyPath() { let ex = expectation(description: "") @@ -97,7 +97,7 @@ class GuaranteeTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testCompactMapValuesByKeyPath() { let ex = expectation(description: "") @@ -154,7 +154,7 @@ class GuaranteeTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testFilterValuesByKeyPath() { let ex = expectation(description: "") From 87a0b0e30b267162938a68cf2e68bbcf862be346 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Tue, 14 Jan 2020 22:03:22 +0100 Subject: [PATCH 10/10] Tests for the functions that are using KeyPath require !swift(>=5.2) (Thenable) --- Tests/CorePromise/ThenableTests.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/CorePromise/ThenableTests.swift b/Tests/CorePromise/ThenableTests.swift index 4063a87f6..a75dc89bb 100644 --- a/Tests/CorePromise/ThenableTests.swift +++ b/Tests/CorePromise/ThenableTests.swift @@ -43,7 +43,7 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testMapByKeyPath() { let ex = expectation(description: "") Promise.value(Person(name: "Max")).map(\.name).done { @@ -110,7 +110,7 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testCompactMapByKeyPath() { let ex = expectation(description: "") Promise.value(Person(name: "Roman", age: 26)).compactMap(\.age).done { @@ -132,7 +132,7 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testMapValuesByKeyPath() { let ex = expectation(description: "") Promise.value([Person(name: "Max"), Person(name: "Roman"), Person(name: "John")]).mapValues(\.name).done { @@ -154,7 +154,7 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testCompactMapValuesByKeyPath() { let ex = expectation(description: "") Promise.value([Person(name: "Max"), Person(name: "Roman", age: 26), Person(name: "John", age: 23)]).compactMapValues(\.age).done { @@ -198,7 +198,7 @@ class ThenableTests: XCTestCase { wait(for: [ex], timeout: 10) } - #if swift(>=4) + #if swift(>=4) && !swift(>=5.2) func testFilterValuesByKeyPath() { let ex = expectation(description: "") Promise.value([Person(name: "Max"), Person(name: "Roman", age: 26, isStudent: false), Person(name: "John", age: 23, isStudent: true)]).filterValues(\.isStudent).done {