From 05cacf79d0b6aa771cb3f91accc5d3e2bb167a8c Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 19 Sep 2024 20:03:51 -0600 Subject: [PATCH] Fix swift 6 concurrency warnings (#19) * Fix swift 6 concurrency warnings * Prefer using enableExperimentalFeature * Improve batch API * Add flag for warnings as errors * Update macOS.yml * Update Package.swift * Update windows.yml * Update ubuntu.yml * Update ubuntu.yml --- .github/workflows/macOS.yml | 4 +- .github/workflows/ubuntu.yml | 22 ++++--- .github/workflows/windows.yml | 8 +-- Package.swift | 8 +-- Sources/Fork/BatchedForkedArray.swift | 12 ++-- .../Fork/Extensions/Actor+ForkedActor.swift | 4 +- .../Sequence+BatchedForkedArray.swift | 50 ++++++++-------- .../Extensions/Sequence+ForkedArray.swift | 34 +++++------ Sources/Fork/Fork.swift | 57 ++++++++++--------- Sources/Fork/ForkedActor.swift | 14 ++--- Sources/Fork/ForkedArray.swift | 43 +++++++------- Tests/ForkTests/BatchedForkedArrayTests.swift | 20 +++---- Tests/ForkTests/ForkTests.swift | 2 +- 13 files changed, 140 insertions(+), 138 deletions(-) diff --git a/.github/workflows/macOS.yml b/.github/workflows/macOS.yml index 7353c39..5366886 100644 --- a/.github/workflows/macOS.yml +++ b/.github/workflows/macOS.yml @@ -9,8 +9,10 @@ on: jobs: build: runs-on: macos-latest - steps: + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: 16.0 - uses: actions/checkout@v3 - name: Build run: swift build -v diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 374be6c..ab88059 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -1,18 +1,22 @@ +# This workflow will build a Swift project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift + name: Ubuntu on: push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] + branches: ["**"] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v + - uses: sersoft-gmbh/swifty-linux-action@v3 + with: + release-version: 6.0 + - uses: actions/checkout@v3 + - name: Build for release + run: swift build -v -c release + - name: Test + run: swift test -v diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 928d7b4..f4819d3 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -2,9 +2,7 @@ name: Windows on: push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] + branches: ["**"] jobs: build: @@ -12,8 +10,8 @@ jobs: steps: - uses: compnerd/gha-setup-swift@main with: - branch: swift-5.9-release - tag: 5.9-RELEASE + branch: swift-6.0-release + tag: 6.0-RELEASE - uses: actions/checkout@v2 - run: swift build diff --git a/Package.swift b/Package.swift index 4fcb97d..f44248f 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.6 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -9,18 +9,16 @@ let package = Package( .iOS(.v13), .watchOS(.v6), .macOS(.v10_15), - .tvOS(.v13) + .tvOS(.v13), + .visionOS(.v1) ], products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "Fork", targets: ["Fork"] ) ], 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: "Fork" ), diff --git a/Sources/Fork/BatchedForkedArray.swift b/Sources/Fork/BatchedForkedArray.swift index 40a37ad..d64fca0 100644 --- a/Sources/Fork/BatchedForkedArray.swift +++ b/Sources/Fork/BatchedForkedArray.swift @@ -1,8 +1,8 @@ /// Using a single array and a single async function, batch the parallelized work for each value of the array -public struct BatchedForkedArray { +public struct BatchedForkedArray: Sendable { private let batchedArray: [[Value]] - private let filter: (Value) async throws -> Bool - private let map: (Value) async throws -> Output + private let filter: @Sendable (Value) async throws -> Bool + private let map: @Sendable (Value) async throws -> Output /// Create a ``BatchedForkedArray`` using a single `Array` /// - Parameters: @@ -13,8 +13,8 @@ public struct BatchedForkedArray { public init( _ array: [Value], batch: UInt, - filter: @escaping (Value) async throws -> Bool, - map: @escaping (Value) async throws -> Output + filter: @Sendable @escaping (Value) async throws -> Bool, + map: @Sendable @escaping (Value) async throws -> Output ) { var index: Int = 0 let batchLimit: UInt = max(batch, 1) @@ -81,7 +81,7 @@ extension BatchedForkedArray { public init( _ array: [Value], batch: UInt, - map: @escaping (Value) async throws -> Output + map: @Sendable @escaping (Value) async throws -> Output ) { self.init(array, batch: batch, filter: { _ in true }, map: map) } diff --git a/Sources/Fork/Extensions/Actor+ForkedActor.swift b/Sources/Fork/Extensions/Actor+ForkedActor.swift index aaf0eb2..d48dffe 100644 --- a/Sources/Fork/Extensions/Actor+ForkedActor.swift +++ b/Sources/Fork/Extensions/Actor+ForkedActor.swift @@ -1,8 +1,8 @@ extension Actor { /// Create a ``ForkedActor`` from the current `Actor` public func fork( - leftOutput: @escaping (_ actor: Self) async throws -> Void, - rightOutput: @escaping (_ actor: Self) async throws -> Void + leftOutput: @Sendable @escaping (_ actor: Self) async throws -> Void, + rightOutput: @Sendable @escaping (_ actor: Self) async throws -> Void ) -> ForkedActor { ForkedActor( actor: self, diff --git a/Sources/Fork/Extensions/Sequence+BatchedForkedArray.swift b/Sources/Fork/Extensions/Sequence+BatchedForkedArray.swift index 5473387..8ab3a3a 100644 --- a/Sources/Fork/Extensions/Sequence+BatchedForkedArray.swift +++ b/Sources/Fork/Extensions/Sequence+BatchedForkedArray.swift @@ -1,9 +1,9 @@ -extension Sequence { +extension Sequence where Element: Sendable { /// Create a ``BatchedForkedArray`` from the current `Sequence` - public func batchedFork( + public func fork( batch: UInt, - filter: @escaping (Element) async throws -> Bool, - map: @escaping (Element) async throws -> Output + filter: @Sendable @escaping (Element) async throws -> Bool, + map: @Sendable @escaping (Element) async throws -> Output ) -> BatchedForkedArray { BatchedForkedArray( Array(self), @@ -14,59 +14,59 @@ extension Sequence { } /// Create a ``BatchedForkedArray`` from the current `Sequence` - public func batchedFork( + public func fork( batch: UInt, - map: @escaping (Element) async throws -> Output + map: @Sendable @escaping (Element) async throws -> Output ) -> BatchedForkedArray { - batchedFork(batch: batch, filter: { _ in true }, map: map) + fork(batch: batch, filter: { _ in true }, map: map) } /// Create a ``BatchedForkedArray`` from the current `Sequence` and get the Output Array - public func batchedForked( + public func forked( batch: UInt, - filter: @escaping (Element) async throws -> Bool, - map: @escaping (Element) async throws -> Output + filter: @Sendable @escaping (Element) async throws -> Bool, + map: @Sendable @escaping (Element) async throws -> Output ) async throws -> [Output] { try await fork(filter: filter, map: map).output() } /// Create a ``BatchedForkedArray`` from the current `Sequence` and get the Output Array - public func batchedForked( + public func forked( batch: UInt, - map: @escaping (Element) async throws -> Output + map: @Sendable @escaping (Element) async throws -> Output ) async throws -> [Output] { - try await batchedForked(batch: batch, filter: { _ in true }, map: map) + try await forked(batch: batch, filter: { _ in true }, map: map) } /// Returns an array containing the results of mapping the given closure over the sequence’s elements. - public func asyncBatchedMap( + public func asyncMap( batch: UInt, - _ transform: @escaping (Element) async throws -> Output + _ transform: @Sendable @escaping (Element) async throws -> Output ) async throws -> [Output] { - try await batchedFork(batch: batch, map: transform).output() + try await fork(batch: batch, map: transform).output() } /// Returns an array containing the results, that aren't nil, of mapping the given closure over the sequence’s elements. - public func asyncBatchedCompactMap( + public func asyncCompactMap( batch: UInt, - _ transform: @escaping (Element) async throws -> Output? + _ transform: @Sendable @escaping (Element) async throws -> Output? ) async throws -> [Output] { - try await batchedFork(batch: batch, map: transform).output().compactMap { $0 } + try await fork(batch: batch, map: transform).output().compactMap { $0 } } /// Returns an array containing only the true results from the given closure over the sequence’s elements. - public func asyncBatchedFilter( + public func asyncFilter( batch: UInt, - _ isIncluded: @escaping (Element) async throws -> Bool + _ isIncluded: @Sendable @escaping (Element) async throws -> Bool ) async throws -> [Element] { - try await batchedFork(batch: batch, filter: isIncluded, map: identity).output() + try await fork(batch: batch, filter: isIncluded, map: identity).output() } /// Calls the given closure for each of the elements in the Sequence. This function uses ``BatchedForkedArray`` and will be parallelized when possible. - public func asyncBatchedForEach( + public func asyncForEach( batch: UInt, - _ transform: @escaping (Element) async throws -> Void + _ transform: @Sendable @escaping (Element) async throws -> Void ) async throws { - _ = try await asyncBatchedMap(batch: batch, transform) + _ = try await asyncMap(batch: batch, transform) } } diff --git a/Sources/Fork/Extensions/Sequence+ForkedArray.swift b/Sources/Fork/Extensions/Sequence+ForkedArray.swift index eb7e739..46a9920 100644 --- a/Sources/Fork/Extensions/Sequence+ForkedArray.swift +++ b/Sources/Fork/Extensions/Sequence+ForkedArray.swift @@ -1,8 +1,8 @@ -extension Sequence { +extension Sequence where Element: Sendable { /// Create a ``ForkedArray`` from the current `Sequence` - public func fork( - filter: @escaping (Element) async throws -> Bool, - map: @escaping (Element) async throws -> Output + public func fork( + filter: @Sendable @escaping (Element) async throws -> Bool, + map: @Sendable @escaping (Element) async throws -> Output ) -> ForkedArray { ForkedArray( Array(self), @@ -12,51 +12,51 @@ extension Sequence { } /// Create a ``ForkedArray`` from the current `Sequence` - public func fork( - map: @escaping (Element) async throws -> Output + public func fork( + map: @Sendable @escaping (Element) async throws -> Output ) -> ForkedArray { fork(filter: { _ in true }, map: map) } /// Create a ``ForkedArray`` from the current `Sequence` and get the Output Array - public func forked( - filter: @escaping (Element) async throws -> Bool, - map: @escaping (Element) async throws -> Output + public func forked( + filter: @Sendable @escaping (Element) async throws -> Bool, + map: @Sendable @escaping (Element) async throws -> Output ) async throws -> [Output] { try await fork(filter: filter, map: map).output() } /// Create a ``ForkedArray`` from the current `Sequence` and get the Output Array - public func forked( - map: @escaping (Element) async throws -> Output + public func forked( + map: @Sendable @escaping (Element) async throws -> Output ) async throws -> [Output] { try await forked(filter: { _ in true }, map: map) } /// Returns an array containing the results of mapping the given closure over the sequence’s elements. - public func asyncMap( - _ transform: @escaping (Element) async throws -> Output + public func asyncMap( + _ transform: @Sendable @escaping (Element) async throws -> Output ) async throws -> [Output] { try await fork(map: transform).output() } /// Returns an array containing the results, that aren't nil, of mapping the given closure over the sequence’s elements. - public func asyncCompactMap( - _ transform: @escaping (Element) async throws -> Output? + public func asyncCompactMap( + _ transform: @Sendable @escaping (Element) async throws -> Output? ) async throws -> [Output] { try await fork(map: transform).output().compactMap { $0 } } /// Returns an array containing only the true results from the given closure over the sequence’s elements. public func asyncFilter( - _ isIncluded: @escaping (Element) async throws -> Bool + _ isIncluded: @Sendable @escaping (Element) async throws -> Bool ) async throws -> [Element] { try await fork(filter: isIncluded, map: identity).output() } /// Calls the given closure for each of the elements in the Sequence. This function uses ``ForkedArray`` and will be parallelized when possible. public func asyncForEach( - _ transform: @escaping (Element) async throws -> Void + _ transform: @Sendable @escaping (Element) async throws -> Void ) async throws { _ = try await asyncMap(transform) } diff --git a/Sources/Fork/Fork.swift b/Sources/Fork/Fork.swift index 15b8766..30b13ab 100644 --- a/Sources/Fork/Fork.swift +++ b/Sources/Fork/Fork.swift @@ -1,18 +1,19 @@ /// Implementation of the [Identity function](https://en.wikipedia.org/wiki/Identity_function) -public func identity(_ value: Value) -> Value { value } +@Sendable +public func identity(_ value: Value) -> Value { value } /// # [Fork](https://en.wikipedia.org/wiki/Fork_(software_development)#Etymology) /// /// Using a single input create two separate async functions that return `LeftOutput` and `RightOutput`. /// -public struct Fork { - +public struct Fork: Sendable { + /// The left async function of the Fork - public let left: () async throws -> LeftOutput - + public let left: @Sendable () async throws -> LeftOutput + /// The right async function of the Fork - public let right: () async throws -> RightOutput - + public let right: @Sendable () async throws -> RightOutput + /// Create a ``Fork`` using a single `Value` that is mapped for the left and right output functions. /// - Parameters: /// - value: The value to be passed into the map functions @@ -21,11 +22,11 @@ public struct Fork { /// - leftOutput: An `async` closure that uses `LeftInput` to return `LeftOutput` /// - rightOutput: An `async` closure that uses `RightInput` to return `RightOutput` public init( - value: @escaping () async throws -> Value, - leftInputMap: @escaping (Value) throws -> LeftInput, - rightInputMap: @escaping (Value) throws -> RightInput, - leftOutput: @escaping (LeftInput) async throws -> LeftOutput, - rightOutput: @escaping (RightInput) async throws -> RightOutput + value: @Sendable @escaping () async throws -> Value, + leftInputMap: @Sendable @escaping (Value) throws -> LeftInput, + rightInputMap: @Sendable @escaping (Value) throws -> RightInput, + leftOutput: @Sendable @escaping (LeftInput) async throws -> LeftOutput, + rightOutput: @Sendable @escaping (RightInput) async throws -> RightOutput ) { left = { try await leftOutput(try leftInputMap(value())) } right = { try await rightOutput(try rightInputMap(value())) } @@ -56,12 +57,12 @@ extension Fork { /// - rightInputMap: Maps the `Value` into `RightInput` /// - leftOutput: An `async` closure that uses `LeftInput` to return `LeftOutput` /// - rightOutput: An `async` closure that uses `RightInput` to return `RightOutput` - public init( + public init( value: Value, - leftInputMap: @escaping (Value) throws -> LeftInput, - rightInputMap: @escaping (Value) throws -> RightInput, - leftOutput: @escaping (LeftInput) async throws -> LeftOutput, - rightOutput: @escaping (RightInput) async throws -> RightOutput + leftInputMap: @Sendable @escaping (Value) throws -> LeftInput, + rightInputMap: @Sendable @escaping (Value) throws -> RightInput, + leftOutput: @Sendable @escaping (LeftInput) async throws -> LeftOutput, + rightOutput: @Sendable @escaping (RightInput) async throws -> RightOutput ) { self.init( value: { value }, @@ -77,10 +78,10 @@ extension Fork { /// - value: The value to be passed into the map functions /// - leftOutput: An `async` closure that uses `LeftInput` to return `LeftOutput` /// - rightOutput: An `async` closure that uses `RightInput` to return `RightOutput` - public init( + public init( value: Value, - leftOutput: @escaping (Value) async throws -> LeftOutput, - rightOutput: @escaping (Value) async throws -> RightOutput + leftOutput: @Sendable @escaping (Value) async throws -> LeftOutput, + rightOutput: @Sendable @escaping (Value) async throws -> RightOutput ) { self.init( value: value, @@ -96,8 +97,8 @@ extension Fork { /// - leftOutput: An `async` closure that returns `LeftOutput` /// - rightOutput: An `async` closure that returns `RightOutput` public init( - leftOutput: @escaping () async throws -> LeftOutput, - rightOutput: @escaping () async throws -> RightOutput + leftOutput: @Sendable @escaping () async throws -> LeftOutput, + rightOutput: @Sendable @escaping () async throws -> RightOutput ) { self.init( value: (), @@ -113,10 +114,10 @@ extension Fork { /// - value: The value to be passed into the map functions /// - leftOutput: An `async` closure that uses `LeftInput` to return `LeftOutput` /// - rightOutput: An `async` closure that uses `RightInput` to return `RightOutput` - public init( - value: @escaping () async throws -> Value, - leftOutput: @escaping (Value) async throws -> LeftOutput, - rightOutput: @escaping (Value) async throws -> RightOutput + public init( + value: @Sendable @escaping () async throws -> Value, + leftOutput: @Sendable @escaping (Value) async throws -> LeftOutput, + rightOutput: @Sendable @escaping (Value) async throws -> RightOutput ) { self.init( value: value, @@ -130,8 +131,8 @@ extension Fork { /// Merge the ``Fork`` and combine the `LeftOutput` and `RightOutput` into a single `Output` /// /// - Returns: The `Output` of the Fork's left and right paths - public func merged( - using: @escaping (LeftOutput, RightOutput) async throws -> Output + public func merged( + using: @Sendable @escaping (LeftOutput, RightOutput) async throws -> Output ) async throws -> Output { try await merge(using: using)() } diff --git a/Sources/Fork/ForkedActor.swift b/Sources/Fork/ForkedActor.swift index b84adc5..accd382 100644 --- a/Sources/Fork/ForkedActor.swift +++ b/Sources/Fork/ForkedActor.swift @@ -1,6 +1,6 @@ /// Using a single actor create two separate async functions that are passed the actor. -public struct ForkedActor { - +public struct ForkedActor: Sendable { + /// The `Actor` used for the fork public var actor: Value @@ -14,8 +14,8 @@ public struct ForkedActor { /// - rightOutput: An `async` closure that uses the `actor` as its input public init( actor: Value, - leftOutput: @escaping (_ actor: Value) async throws -> Void, - rightOutput: @escaping (_ actor: Value) async throws -> Void + leftOutput: @Sendable @escaping (_ actor: Value) async throws -> Void, + rightOutput: @Sendable @escaping (_ actor: Value) async throws -> Void ) { self.actor = actor self.fork = Fork( @@ -48,10 +48,10 @@ extension ForkedActor { /// - value: Any value to be passed into the map functions. This value is wrapped into an `actor` using ``KeyPathActor``. /// - leftOutput: An `async` closure that uses the `actor` as its input /// - rightOutput: An `async` closure that uses the `actor` as its input - public init( + public init( value: Input, - leftOutput: @escaping (_ actor: Value) async throws -> Void, - rightOutput: @escaping (_ actor: Value) async throws -> Void + leftOutput: @Sendable @escaping (_ actor: Value) async throws -> Void, + rightOutput: @Sendable @escaping (_ actor: Value) async throws -> Void ) where Value == KeyPathActor { self.init( actor: KeyPathActor(value: value), diff --git a/Sources/Fork/ForkedArray.swift b/Sources/Fork/ForkedArray.swift index 10fb21d..fe8352d 100644 --- a/Sources/Fork/ForkedArray.swift +++ b/Sources/Fork/ForkedArray.swift @@ -1,13 +1,13 @@ /// Using a single array and a single async function, parallelize the work for each value of the array -public struct ForkedArray { - enum ForkType { +public struct ForkedArray: Sendable { + enum ForkType: Sendable{ case none case single(Value) case fork(Fork) } - private let filter: (Value) async throws -> Bool - private let map: (Value) async throws -> Output + private let filter: @Sendable (Value) async throws -> Bool + private let map: @Sendable (Value) async throws -> Output private let fork: Fork /// The input array used to get the output @@ -20,8 +20,8 @@ public struct ForkedArray { /// - map: An `async` closure that uses the `Array.Element` as its input public init( _ array: [Value], - filter: @escaping (Value) async throws -> Bool, - map: @escaping (Value) async throws -> Output + filter: @Sendable @escaping (Value) async throws -> Bool, + map: @Sendable @escaping (Value) async throws -> Output ) { self.array = array self.filter = filter @@ -37,7 +37,7 @@ public struct ForkedArray { case .single(let value): self.fork = Fork( value: value, - leftOutput: ForkType.single, + leftOutput: { ForkType.single($0) }, rightOutput: { _ in .none } ) case .fork(let fork): @@ -63,13 +63,14 @@ extension ForkedArray { /// - map: An `async` closure that uses the `Array.Element` as its input public init( _ array: [Value], - map: @escaping (Value) async throws -> Output + map: @Sendable @escaping (Value) async throws -> Output ) { self.init(array, filter: { _ in true }, map: map) } } extension ForkedArray { + @Sendable private static func split( array: [Value] ) -> ForkType { @@ -85,8 +86,8 @@ extension ForkedArray { value: array, leftInputMap: { $0[0] }, rightInputMap: { $0[1] }, - leftOutput: ForkType.single, - rightOutput: ForkType.single + leftOutput: { ForkType.single($0) }, + rightOutput: { ForkType.single($0) } ) ) default: @@ -96,7 +97,7 @@ extension ForkedArray { Fork( value: array, leftInputMap: { Array($0[0 ..< midPoint]) }, - rightInputMap: { Array($0[midPoint ... count - 1]) }, + rightInputMap: { Array($0[midPoint ..< count]) }, leftOutput: split(array:), rightOutput: split(array:) ) @@ -107,8 +108,8 @@ extension ForkedArray { extension ForkedArray.ForkType { func output( - isIncluded: @escaping (Value) async throws -> Bool, - transform: @escaping (Value) async throws -> Output + isIncluded: @Sendable @escaping (Value) async throws -> Bool, + transform: @Sendable @escaping (Value) async throws -> Output ) async throws -> [Output] { switch self { case .none: @@ -120,16 +121,14 @@ extension ForkedArray.ForkType { return [try await transform(value)] } case let .fork(fork): - return try await fork.merged( - using: { leftType, rightType in - try await Task.withCheckedCancellation { - async let leftOutput = try leftType.output(isIncluded: isIncluded, transform: transform) - async let rightOutput = try rightType.output(isIncluded: isIncluded, transform: transform) - - return try await leftOutput + rightOutput - } + return try await fork.merged { leftType, rightType in + try await Task.withCheckedCancellation { + async let leftOutput = try leftType.output(isIncluded: isIncluded, transform: transform) + async let rightOutput = try rightType.output(isIncluded: isIncluded, transform: transform) + + return try await leftOutput + rightOutput } - ) + } } } } diff --git a/Tests/ForkTests/BatchedForkedArrayTests.swift b/Tests/ForkTests/BatchedForkedArrayTests.swift index 18ddc3d..8ce4517 100644 --- a/Tests/ForkTests/BatchedForkedArrayTests.swift +++ b/Tests/ForkTests/BatchedForkedArrayTests.swift @@ -19,7 +19,7 @@ final class BatchedForkedArrayTests: XCTestCase { func testBatchedForkedArrayStream_x() async throws { let photoNames = [Int](0 ..< 100) - let batchedForkedArray = photoNames.batchedFork( + let batchedForkedArray = photoNames.fork( batch: 5, map: { "\($0)" } ) @@ -49,7 +49,7 @@ final class BatchedForkedArrayTests: XCTestCase { "Hello", " ", // First batch "World", "!" // Second batch ] - .asyncBatchedForEach(batch: 2) { print($0) } + .asyncForEach(batch: 2) { print($0) } } func testBatchedForkedArray_none() async throws { @@ -67,7 +67,7 @@ final class BatchedForkedArrayTests: XCTestCase { let photoNames = ["one"] @Sendable func isValidPhoto(named: String) async -> Bool { true } - let photos = try await photoNames.asyncBatchedFilter(batch: 0, isValidPhoto(named:)) + let photos = try await photoNames.asyncFilter(batch: 0, isValidPhoto(named:)) XCTAssertEqual(photos, photoNames) } @@ -76,7 +76,7 @@ final class BatchedForkedArrayTests: XCTestCase { let photoNames = ["one", "two"] @Sendable func downloadPhoto(named: String) async -> String { named } - let photos = try await photoNames.batchedForked( + let photos = try await photoNames.forked( batch: 2, map: downloadPhoto(named:) ) @@ -88,7 +88,7 @@ final class BatchedForkedArrayTests: XCTestCase { let photoNames = ["one", "two", "three"] @Sendable func downloadPhoto(named: String) async -> String { named } - let photos = try await photoNames.asyncBatchedMap(batch: 2, downloadPhoto(named:)) + let photos = try await photoNames.asyncMap(batch: 2, downloadPhoto(named:)) XCTAssertEqual(photos, photoNames) } @@ -96,7 +96,7 @@ final class BatchedForkedArrayTests: XCTestCase { let photoNames = (0 ... Int.random(in: 3 ..< 100)).map(\.description) @Sendable func downloadPhoto(named: String) async -> String { named } - let forkedArray = photoNames.batchedFork(batch: 10, map: downloadPhoto(named:)) + let forkedArray = photoNames.fork(batch: 10, map: downloadPhoto(named:)) let photos = try await forkedArray.output() XCTAssertEqual(photos, photoNames) @@ -110,7 +110,7 @@ final class BatchedForkedArrayTests: XCTestCase { return number.description } - let compactedArray = try await photoNames.asyncBatchedCompactMap(batch: 10, asyncFilter(number:)) + let compactedArray = try await photoNames.asyncCompactMap(batch: 10, asyncFilter(number:)) XCTAssertEqual(compactedArray.count, photoNames.count / 2) } @@ -119,7 +119,7 @@ final class BatchedForkedArrayTests: XCTestCase { let photoNames = ["Hello", " ", "World", "!"] @Sendable func downloadPhoto(named: String) async -> String { named } - let forkedArray = photoNames.batchedFork(batch: 2, map: downloadPhoto(named:)) + let forkedArray = photoNames.fork(batch: 2, map: downloadPhoto(named:)) let photos = try await forkedArray.output() XCTAssertEqual(photos, photoNames) @@ -128,7 +128,7 @@ final class BatchedForkedArrayTests: XCTestCase { func testBatchedForkedArraySet() async throws { let set = Set(0 ..< 9) - let outputArray = try await set.asyncBatchedMap(batch: 3, identity) + let outputArray = try await set.asyncMap(batch: 3, identity) XCTAssertEqual(outputArray, Array(set)) } @@ -136,7 +136,7 @@ final class BatchedForkedArrayTests: XCTestCase { func testBatchedForkedArrayDictionary() async throws { let dictionary: [String: String] = [:] - let outputArray = try await dictionary.batchedForked( + let outputArray = try await dictionary.forked( batch: 1, filter: { (key: String, value: String) in return true diff --git a/Tests/ForkTests/ForkTests.swift b/Tests/ForkTests/ForkTests.swift index a545b33..51f8f27 100644 --- a/Tests/ForkTests/ForkTests.swift +++ b/Tests/ForkTests/ForkTests.swift @@ -32,7 +32,7 @@ final class ForkTests: XCTestCase { func testForkClosure() async throws { let fork = Fork( - value: UUID.init, + value: { UUID() }, leftOutput: { $0.uuidString == "UUID" }, rightOutput: { Array($0.uuidString.reversed().map(\.description)) } )