diff --git a/Evolution/NNNN-lazy.md b/0009-async.md similarity index 71% rename from Evolution/NNNN-lazy.md rename to 0009-async.md index f2d84580..897e57b8 100644 --- a/Evolution/NNNN-lazy.md +++ b/0009-async.md @@ -1,16 +1,16 @@ -# AsyncLazySequence +# AsyncSyncSequence * Proposal: [NNNN](NNNN-lazy.md) * Authors: [Philippe Hausler](https://github.com/phausler) * Status: **Implemented** * Implementation: - [Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncLazySequence.swift) | + [Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncSyncSequence.swift) | [Tests](https://github.com/apple/swift-async-algorithms/blob/main/Tests/AsyncAlgorithmsTests/TestLazy.swift) ## Introduction -`AsyncLazySequence` converts a non-asynchronous sequence into an asynchronous one. +`AsyncSyncSequence` converts a non-asynchronous sequence into an asynchronous one. This operation is available for all `Sequence` types. @@ -22,19 +22,19 @@ let characters = "abcde".async This transformation can be useful to test operations specifically available on `AsyncSequence` but also is useful to combine with other `AsyncSequence` types to provide well known sources of data. -The `.async` property returns an `AsyncLazySequence` that is generic upon the base `Sequence` it was constructed from. +The `.async` property returns an `AsyncSyncSequence` that is generic upon the base `Sequence` it was constructed from. ```swift extension Sequence { - public var async: AsyncLazySequence { get } + public var async: AsyncSyncSequence { get } } -public struct AsyncLazySequence: AsyncSequence { +public struct AsyncSyncSequence: AsyncSequence { ... } -extension AsyncLazySequence: Sendable where Base: Sendable { } -extension AsyncLazySequence.Iterator: Sendable where Base.Iterator: Sendable { } +extension AsyncSyncSequence: Sendable where Base: Sendable { } +extension AsyncSyncSequence.Iterator: Sendable where Base.Iterator: Sendable { } ``` ### Naming @@ -45,4 +45,4 @@ succinct name in inspiration from `.lazy`, and the type is named in reference to ## Effect on API resilience -`AsyncLazySequence` has a trivial implementation and is marked as `@frozen` and `@inlinable`. This removes the ability of this type and functions to be ABI resilient boundaries at the benefit of being highly optimizable. +`AsyncSyncSequence` has a trivial implementation and is marked as `@frozen` and `@inlinable`. This removes the ability of this type and functions to be ABI resilient boundaries at the benefit of being highly optimizable. diff --git a/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Effects.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Effects.md index 5d7a5967..82830bb6 100644 --- a/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Effects.md +++ b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Effects.md @@ -34,8 +34,8 @@ | `AsyncInterspersedSequence.Iterator` | rethrows | Not Sendable| | `AsyncJoinedSequence` | rethrows | Conditional | | `AsyncJoinedSequence.Iterator` | rethrows | Not Sendable| -| `AsyncLazySequence` | non-throwing | Conditional | -| `AsyncLazySequence.Iterator` | non-throwing | Not Sendable| +| `AsyncSyncSequence` | non-throwing | Conditional | +| `AsyncSyncSequence.Iterator` | non-throwing | Not Sendable| | `AsyncLimitBuffer` | non-throwing | Sendable | | `AsyncMerge2Sequence` | rethrows | Sendable | | `AsyncMerge2Sequence.Iterator` | rethrows | Not Sendable| diff --git a/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Lazy.md b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Lazy.md index 3254ab08..fe5dda9d 100644 --- a/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Lazy.md +++ b/Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Lazy.md @@ -1,6 +1,6 @@ -# AsyncLazySequence +# AsyncSyncSequence -[[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncLazySequence.swift) | +[[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncSyncSequence.swift) | [Tests](https://github.com/apple/swift-async-algorithms/blob/main/Tests/AsyncAlgorithmsTests/TestLazy.swift)] Converts a non-asynchronous sequence into an asynchronous one. @@ -17,19 +17,19 @@ to combine with other `AsyncSequence` types to provide well known sources of dat ## Detailed Design -The `.async` property returns an `AsyncLazySequence` that is generic upon the base `Sequence` it was constructed from. +The `.async` property returns an `AsyncSyncSequence` that is generic upon the base `Sequence` it was constructed from. ```swift extension Sequence { - public var async: AsyncLazySequence { get } + public var async: AsyncSyncSequence { get } } -public struct AsyncLazySequence: AsyncSequence { +public struct AsyncSyncSequence: AsyncSequence { ... } -extension AsyncLazySequence: Sendable where Base: Sendable { } -extension AsyncLazySequence.Iterator: Sendable where Base.Iterator: Sendable { } +extension AsyncSyncSequence: Sendable where Base: Sendable { } +extension AsyncSyncSequence.Iterator: Sendable where Base.Iterator: Sendable { } ``` ### Naming diff --git a/Sources/AsyncAlgorithms/AsyncChunksOfCountOrSignalSequence.swift b/Sources/AsyncAlgorithms/AsyncChunksOfCountOrSignalSequence.swift index 8e4ce7b5..3fce684d 100644 --- a/Sources/AsyncAlgorithms/AsyncChunksOfCountOrSignalSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncChunksOfCountOrSignalSequence.swift @@ -70,7 +70,7 @@ public struct AsyncChunksOfCountOrSignalSequence typealias EitherMappedSignal = AsyncMapSequence - typealias ChainedBase = AsyncChain2Sequence> + typealias ChainedBase = AsyncChain2Sequence> typealias Merged = AsyncMerge2Sequence let count: Int? diff --git a/Sources/AsyncAlgorithms/AsyncLazySequence.swift b/Sources/AsyncAlgorithms/AsyncSyncSequence.swift similarity index 89% rename from Sources/AsyncAlgorithms/AsyncLazySequence.swift rename to Sources/AsyncAlgorithms/AsyncSyncSequence.swift index 9a8abd77..6710df7c 100644 --- a/Sources/AsyncAlgorithms/AsyncLazySequence.swift +++ b/Sources/AsyncAlgorithms/AsyncSyncSequence.swift @@ -14,8 +14,8 @@ extension Sequence { /// but on which operations, such as `map` and `filter`, are /// implemented asynchronously. @inlinable - public var async: AsyncLazySequence { - AsyncLazySequence(self) + public var async: AsyncSyncSequence { + AsyncSyncSequence(self) } } @@ -28,7 +28,7 @@ extension Sequence { /// This functions similarly to `LazySequence` by accessing elements sequentially /// in the iterator's `next()` method. @frozen -public struct AsyncLazySequence: AsyncSequence { +public struct AsyncSyncSequence: AsyncSequence { public typealias Element = Base.Element @frozen @@ -66,4 +66,4 @@ public struct AsyncLazySequence: AsyncSequence { } } -extension AsyncLazySequence: Sendable where Base: Sendable { } +extension AsyncSyncSequence: Sendable where Base: Sendable { } diff --git a/Tests/AsyncAlgorithmsTests/TestJoin.swift b/Tests/AsyncAlgorithmsTests/TestJoin.swift index 04fd1772..91de1ef9 100644 --- a/Tests/AsyncAlgorithmsTests/TestJoin.swift +++ b/Tests/AsyncAlgorithmsTests/TestJoin.swift @@ -13,8 +13,8 @@ import XCTest import AsyncAlgorithms extension Sequence where Element: Sequence, Element.Element: Equatable & Sendable { - func nestedAsync(throwsOn bad: Element.Element) -> AsyncLazySequence<[AsyncThrowingMapSequence,Element.Element>]> { - let array: [AsyncThrowingMapSequence,Element.Element>] = self.map { $0.async }.map { + func nestedAsync(throwsOn bad: Element.Element) -> AsyncSyncSequence<[AsyncThrowingMapSequence,Element.Element>]> { + let array: [AsyncThrowingMapSequence,Element.Element>] = self.map { $0.async }.map { $0.map { try throwOn(bad, $0) } } return array.async @@ -22,7 +22,7 @@ extension Sequence where Element: Sequence, Element.Element: Equatable & Sendabl } extension Sequence where Element: Sequence, Element.Element: Sendable { - var nestedAsync : AsyncLazySequence<[AsyncLazySequence]> { + var nestedAsync : AsyncSyncSequence<[AsyncSyncSequence]> { return self.map { $0.async }.async } } @@ -55,7 +55,7 @@ final class TestJoinedBySeparator: XCTestCase { } func test_join_empty() async { - let sequences = [AsyncLazySequence<[Int]>]().async + let sequences = [AsyncSyncSequence<[Int]>]().async var iterator = sequences.joined(separator: [-1, -2, -3].async).makeAsyncIterator() let expected = [Int]() var actual = [Int]() @@ -105,7 +105,7 @@ final class TestJoinedBySeparator: XCTestCase { } func test_cancellation() async { - let source : AsyncLazySequence<[AsyncLazySequence>]> = [Indefinite(value: "test").async].async + let source : AsyncSyncSequence<[AsyncSyncSequence>]> = [Indefinite(value: "test").async].async let sequence = source.joined(separator: ["past indefinite"].async) let finished = expectation(description: "finished") let iterated = expectation(description: "iterated") @@ -158,7 +158,7 @@ final class TestJoined: XCTestCase { } func test_join_empty() async { - let sequences = [AsyncLazySequence<[Int]>]().async + let sequences = [AsyncSyncSequence<[Int]>]().async var iterator = sequences.joined().makeAsyncIterator() let expected = [Int]() var actual = [Int]() @@ -189,7 +189,7 @@ final class TestJoined: XCTestCase { } func test_cancellation() async { - let source : AsyncLazySequence<[AsyncLazySequence>]> = [Indefinite(value: "test").async].async + let source : AsyncSyncSequence<[AsyncSyncSequence>]> = [Indefinite(value: "test").async].async let sequence = source.joined() let finished = expectation(description: "finished") let iterated = expectation(description: "iterated")