Skip to content

Commit

Permalink
Added support for Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitribouniol committed Jun 19, 2024
1 parent db3e026 commit adeb5fb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let package = Package(
name: "AsyncSequenceReader",
dependencies: [],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
.enableExperimentalFeature("StrictConcurrency"),
]
),
.testTarget(
Expand Down
38 changes: 38 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -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"]),
]
)
4 changes: 2 additions & 2 deletions Sources/AsyncSequenceReader/AsyncReadSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension AsyncIteratorProtocol {
public mutating func transform<Transformed, ReadSequence: AsyncReadSequence>(
with sequenceTransform: (ReadSequence) async throws -> Transformed,
readSequenceFactory: (inout AsyncBufferedIterator<Self>) -> 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() {
Expand All @@ -54,7 +54,7 @@ extension AsyncBufferedIterator {
public mutating func transform<Transformed, ReadSequence: AsyncReadSequence>(
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() {
Expand Down
16 changes: 8 additions & 8 deletions Sources/AsyncSequenceReader/AsyncReadUpToElementsSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ extension AsyncIteratorProtocol {
public mutating func collect<Transformed>(
upToIncluding termination: Element,
sequenceTransform: (AsyncReadUpToElementsSequence<Self>) 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.
Expand Down Expand Up @@ -221,8 +221,8 @@ extension AsyncIteratorProtocol {
public mutating func collect<Transformed>(
upToIncluding termination: [Element],
sequenceTransform: (AsyncReadUpToElementsSequence<Self>) 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.
Expand Down Expand Up @@ -335,8 +335,8 @@ extension AsyncBufferedIterator {
public mutating func collect<Transformed>(
upToIncluding termination: Element,
sequenceTransform: (AsyncReadUpToElementsSequence<Self>) 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.
Expand Down Expand Up @@ -372,8 +372,8 @@ extension AsyncBufferedIterator {
public mutating func collect<Transformed>(
upToIncluding termination: [Element],
sequenceTransform: (AsyncReadUpToElementsSequence<BaseIterator>) 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand All @@ -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 {
Expand Down

0 comments on commit adeb5fb

Please sign in to comment.