From c24d05c0c2c175088ddb2e5c55432eedd7373d63 Mon Sep 17 00:00:00 2001 From: Dimitri Bouniol Date: Wed, 19 Jun 2024 01:32:19 -0700 Subject: [PATCH] Added support for Swift 6 --- Package@swift-5.8.swift | 2 +- Package@swift-6.0.swift | 38 +++++++++++++++++++ .../AsyncReadSequence.swift | 4 +- .../AsyncReadUpToCountSequence.swift | 8 ++-- .../AsyncReadUpToElementsSequence.swift | 24 ++++++------ .../AsyncReadUpToElementsSequenceTests.swift | 16 ++++---- 6 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 Package@swift-6.0.swift diff --git a/Package@swift-5.8.swift b/Package@swift-5.8.swift index 79bf26c..cb9f6b3 100644 --- a/Package@swift-5.8.swift +++ b/Package@swift-5.8.swift @@ -28,7 +28,7 @@ let package = Package( name: "AsyncSequenceReader", dependencies: [], swiftSettings: [ - .enableExperimentalFeature("StrictConcurrency") + .enableExperimentalFeature("StrictConcurrency"), ] ), .testTarget( diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift new file mode 100644 index 0000000..837b5b0 --- /dev/null +++ b/Package@swift-6.0.swift @@ -0,0 +1,38 @@ +// swift-tools-version:6.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "AsyncSequenceReader", + platforms: [ + .macOS(.v10_15), + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "AsyncSequenceReader", + targets: ["AsyncSequenceReader"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "AsyncSequenceReader", + dependencies: [], + swiftSettings: [ + .swiftLanguageVersion(.v6), + ] + ), + .testTarget( + name: "AsyncSequenceReaderTests", + dependencies: ["AsyncSequenceReader"]), + ] +) diff --git a/Sources/AsyncSequenceReader/AsyncReadSequence.swift b/Sources/AsyncSequenceReader/AsyncReadSequence.swift index 05d38d1..362613b 100644 --- a/Sources/AsyncSequenceReader/AsyncReadSequence.swift +++ b/Sources/AsyncSequenceReader/AsyncReadSequence.swift @@ -29,7 +29,7 @@ extension AsyncIteratorProtocol { public mutating func transform( with sequenceTransform: (ReadSequence) async throws -> Transformed, readSequenceFactory: (inout AsyncBufferedIterator) -> ReadSequence - ) async rethrows -> Transformed? where ReadSequence.BaseIterator == Self { + ) async throws -> Transformed? where ReadSequence.BaseIterator == Self { var results: Transformed? = nil var wrappedIterator = AsyncBufferedIterator(self) if try await wrappedIterator.hasMoreData() { @@ -54,7 +54,7 @@ extension AsyncBufferedIterator { public mutating func transform( with sequenceTransform: (ReadSequence) async throws -> Transformed, readSequenceFactory: (inout Self) -> ReadSequence - ) async rethrows -> Transformed? where ReadSequence.BaseIterator == BaseIterator { + ) async throws -> Transformed? where ReadSequence.BaseIterator == BaseIterator { var results: Transformed? = nil if try await self.hasMoreData() { diff --git a/Sources/AsyncSequenceReader/AsyncReadUpToCountSequence.swift b/Sources/AsyncSequenceReader/AsyncReadUpToCountSequence.swift index c352787..c38ad5d 100644 --- a/Sources/AsyncSequenceReader/AsyncReadUpToCountSequence.swift +++ b/Sources/AsyncSequenceReader/AsyncReadUpToCountSequence.swift @@ -82,7 +82,7 @@ extension AsyncIteratorProtocol { public mutating func collect( _ count: Int, sequenceTransform: (AsyncReadUpToCountSequence) async throws -> Transformed - ) async rethrows -> Transformed? { + ) async throws -> Transformed? { assert(count >= 0, "count must be larger than 0") return try await collect(min: count, max: count, sequenceTransform: sequenceTransform) } @@ -121,7 +121,7 @@ extension AsyncIteratorProtocol { min minCount: Int = 0, max maxCount: Int, sequenceTransform: (AsyncReadUpToCountSequence) async throws -> Transformed - ) async rethrows -> Transformed? { + ) async throws -> Transformed? { try await transform(with: sequenceTransform) { .init($0, minCount: minCount, maxCount: maxCount) } } } @@ -159,7 +159,7 @@ extension AsyncBufferedIterator { public mutating func collect( _ count: Int, sequenceTransform: (AsyncReadUpToCountSequence) async throws -> Transformed - ) async rethrows -> Transformed? { + ) async throws -> Transformed? { assert(count >= 0, "count must be larger than 0") return try await collect(min: count, max: count, sequenceTransform: sequenceTransform) } @@ -198,7 +198,7 @@ extension AsyncBufferedIterator { min minCount: Int = 0, max maxCount: Int, sequenceTransform: (AsyncReadUpToCountSequence) async throws -> Transformed - ) async rethrows -> Transformed? { + ) async throws -> Transformed? { try await transform(with: sequenceTransform) { .init($0, minCount: minCount, maxCount: maxCount) } } } diff --git a/Sources/AsyncSequenceReader/AsyncReadUpToElementsSequence.swift b/Sources/AsyncSequenceReader/AsyncReadUpToElementsSequence.swift index b2fdf41..3d576f9 100644 --- a/Sources/AsyncSequenceReader/AsyncReadUpToElementsSequence.swift +++ b/Sources/AsyncSequenceReader/AsyncReadUpToElementsSequence.swift @@ -184,8 +184,8 @@ extension AsyncIteratorProtocol { public mutating func collect( upToIncluding termination: Element, sequenceTransform: (AsyncReadUpToElementsSequence) async -> Transformed - ) async -> Transformed? where Element: Equatable { - await collect(upToIncluding: [termination], sequenceTransform: sequenceTransform) + ) async throws -> Transformed? where Element: Equatable { + try await collect(upToIncluding: [termination], sequenceTransform: sequenceTransform) } /// Collect elements into a sequence until the termination sequence is encountered, and transform it using the provided closure. @@ -221,8 +221,8 @@ extension AsyncIteratorProtocol { public mutating func collect( upToIncluding termination: [Element], sequenceTransform: (AsyncReadUpToElementsSequence) async -> Transformed - ) async -> Transformed? where Element: Equatable { - await transform(with: sequenceTransform) { .init($0, termination: termination) } + ) async throws -> Transformed? where Element: Equatable { + try await transform(with: sequenceTransform) { .init($0, termination: termination) } } /// Collect elements into a sequence until the termination sequence is encountered, and transform it using the provided closure. @@ -258,7 +258,7 @@ extension AsyncIteratorProtocol { public mutating func collect( upToIncluding termination: Element, sequenceTransform: (AsyncReadUpToElementsSequence) async throws -> Transformed - ) async rethrows -> Transformed? where Element: Equatable { + ) async throws -> Transformed? where Element: Equatable { try await collect(upToIncluding: [termination], sequenceTransform: sequenceTransform) } @@ -295,7 +295,7 @@ extension AsyncIteratorProtocol { public mutating func collect( upToIncluding termination: [Element], sequenceTransform: (AsyncReadUpToElementsSequence) async throws -> Transformed - ) async rethrows -> Transformed? where Element: Equatable { + ) async throws -> Transformed? where Element: Equatable { try await transform(with: sequenceTransform) { .init($0, termination: termination) } } } @@ -335,8 +335,8 @@ extension AsyncBufferedIterator { public mutating func collect( upToIncluding termination: Element, sequenceTransform: (AsyncReadUpToElementsSequence) async -> Transformed - ) async -> Transformed? where Element: Equatable { - await collect(upToIncluding: [termination], sequenceTransform: sequenceTransform) + ) async throws -> Transformed? where Element: Equatable { + try await collect(upToIncluding: [termination], sequenceTransform: sequenceTransform) } /// Collect elements into a sequence until the termination sequence is encountered, and transform it using the provided closure. @@ -372,8 +372,8 @@ extension AsyncBufferedIterator { public mutating func collect( upToIncluding termination: [Element], sequenceTransform: (AsyncReadUpToElementsSequence) async -> Transformed - ) async -> Transformed? where Element: Equatable { - await transform(with: sequenceTransform) { .init($0, termination: termination) } + ) async throws -> Transformed? where Element: Equatable { + try await transform(with: sequenceTransform) { .init($0, termination: termination) } } /// Collect elements into a sequence until the termination sequence is encountered, and transform it using the provided closure. @@ -409,7 +409,7 @@ extension AsyncBufferedIterator { public mutating func collect( upToIncluding termination: Element, sequenceTransform: (AsyncReadUpToElementsSequence) async throws -> Transformed - ) async rethrows -> Transformed? where Element: Equatable { + ) async throws -> Transformed? where Element: Equatable { try await collect(upToIncluding: [termination], sequenceTransform: sequenceTransform) } @@ -446,7 +446,7 @@ extension AsyncBufferedIterator { public mutating func collect( upToIncluding termination: [Element], sequenceTransform: (AsyncReadUpToElementsSequence) async throws -> Transformed - ) async rethrows -> Transformed? where Element: Equatable { + ) async throws -> Transformed? where Element: Equatable { try await transform(with: sequenceTransform) { .init($0, termination: termination) } } } diff --git a/Tests/AsyncSequenceReaderTests/AsyncReadUpToElementsSequenceTests.swift b/Tests/AsyncSequenceReaderTests/AsyncReadUpToElementsSequenceTests.swift index c3504b8..88e0a9d 100644 --- a/Tests/AsyncSequenceReaderTests/AsyncReadUpToElementsSequenceTests.swift +++ b/Tests/AsyncSequenceReaderTests/AsyncReadUpToElementsSequenceTests.swift @@ -16,7 +16,7 @@ final class AsyncReadUpToElementsSequenceTests: XCTestCase { let testStream = TestSequence(base: "apple orange banana kiwi kumquat pear pineapple") let results = testStream.iteratorMap { iterator -> String? in - let word = await iterator.collect(upToIncluding: " ") { sequence -> String in + let word = try await iterator.collect(upToIncluding: " ") { sequence -> String in await sequence.reduce(into: "") { $0.append($1) } } @@ -28,13 +28,13 @@ final class AsyncReadUpToElementsSequenceTests: XCTestCase { var resultsIterator = results.makeAsyncIterator() - await AsyncXCTAssertEqual(await resultsIterator.next(), "apple") - await AsyncXCTAssertEqual(await resultsIterator.next(), "orange") - await AsyncXCTAssertEqual(await resultsIterator.next(), "banana") - await AsyncXCTAssertEqual(await resultsIterator.next(), "kiwi") - await AsyncXCTAssertEqual(await resultsIterator.next(), "kumquat") - await AsyncXCTAssertEqual(await resultsIterator.next(), "pear") - await AsyncXCTAssertEqual(await resultsIterator.next(), "pineapple") + try await AsyncXCTAssertEqual(await resultsIterator.next(), "apple") + try await AsyncXCTAssertEqual(await resultsIterator.next(), "orange") + try await AsyncXCTAssertEqual(await resultsIterator.next(), "banana") + try await AsyncXCTAssertEqual(await resultsIterator.next(), "kiwi") + try await AsyncXCTAssertEqual(await resultsIterator.next(), "kumquat") + try await AsyncXCTAssertEqual(await resultsIterator.next(), "pear") + try await AsyncXCTAssertEqual(await resultsIterator.next(), "pineapple") } func testIteratorMapUpToIncluding() async throws {