mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-25 04:27:48 +00:00
Rename AsyncLazySequence to AsyncSyncSequence per review feedback (#246)
* Rename AsyncLazySequence to AsyncSyncSequence per review feedback * Rename and number the async proposal
This commit is contained in:
1 parent
e7b9b6039d
commit
a07a3f41b5
6 files changed
+30
-30
No files matched your search
@@ -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<Self> { get }
|
||||
public var async: AsyncSyncSequence<Self> { get }
|
||||
}
|
||||
|
||||
public struct AsyncLazySequence<Base: Sequence>: AsyncSequence {
|
||||
public struct AsyncSyncSequence<Base: Sequence>: 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.
|
||||
@@ -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|
|
||||
|
||||
@@ -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<Self> { get }
|
||||
public var async: AsyncSyncSequence<Self> { get }
|
||||
}
|
||||
|
||||
public struct AsyncLazySequence<Base: Sequence>: AsyncSequence {
|
||||
public struct AsyncSyncSequence<Base: Sequence>: 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
|
||||
|
||||
@@ -70,7 +70,7 @@ public struct AsyncChunksOfCountOrSignalSequence<Base: AsyncSequence, Collected:
|
||||
public struct Iterator: AsyncIteratorProtocol {
|
||||
typealias EitherMappedBase = AsyncMapSequence<Base, Either>
|
||||
typealias EitherMappedSignal = AsyncMapSequence<Signal, Either>
|
||||
typealias ChainedBase = AsyncChain2Sequence<EitherMappedBase, AsyncLazySequence<[Either]>>
|
||||
typealias ChainedBase = AsyncChain2Sequence<EitherMappedBase, AsyncSyncSequence<[Either]>>
|
||||
typealias Merged = AsyncMerge2Sequence<ChainedBase, EitherMappedSignal>
|
||||
|
||||
let count: Int?
|
||||
|
||||
+4
-4
@@ -14,8 +14,8 @@ extension Sequence {
|
||||
/// but on which operations, such as `map` and `filter`, are
|
||||
/// implemented asynchronously.
|
||||
@inlinable
|
||||
public var async: AsyncLazySequence<Self> {
|
||||
AsyncLazySequence(self)
|
||||
public var async: AsyncSyncSequence<Self> {
|
||||
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<Base: Sequence>: AsyncSequence {
|
||||
public struct AsyncSyncSequence<Base: Sequence>: AsyncSequence {
|
||||
public typealias Element = Base.Element
|
||||
|
||||
@frozen
|
||||
@@ -66,4 +66,4 @@ public struct AsyncLazySequence<Base: Sequence>: AsyncSequence {
|
||||
}
|
||||
}
|
||||
|
||||
extension AsyncLazySequence: Sendable where Base: Sendable { }
|
||||
extension AsyncSyncSequence: Sendable where Base: Sendable { }
|
||||
@@ -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<AsyncLazySequence<Element>,Element.Element>]> {
|
||||
let array: [AsyncThrowingMapSequence<AsyncLazySequence<Element>,Element.Element>] = self.map { $0.async }.map {
|
||||
func nestedAsync(throwsOn bad: Element.Element) -> AsyncSyncSequence<[AsyncThrowingMapSequence<AsyncSyncSequence<Element>,Element.Element>]> {
|
||||
let array: [AsyncThrowingMapSequence<AsyncSyncSequence<Element>,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<Element>]> {
|
||||
var nestedAsync : AsyncSyncSequence<[AsyncSyncSequence<Element>]> {
|
||||
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<String>>]> = [Indefinite(value: "test").async].async
|
||||
let source : AsyncSyncSequence<[AsyncSyncSequence<Indefinite<String>>]> = [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<String>>]> = [Indefinite(value: "test").async].async
|
||||
let source : AsyncSyncSequence<[AsyncSyncSequence<Indefinite<String>>]> = [Indefinite(value: "test").async].async
|
||||
let sequence = source.joined()
|
||||
let finished = expectation(description: "finished")
|
||||
let iterated = expectation(description: "iterated")
|
||||
|
||||
Reference in new issue
Block a user