Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename AsyncLazySequence to AsyncSyncSequence per review feedback #246

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Evolution/NNNN-lazy.md → 0009-async.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand All @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
14 changes: 7 additions & 7 deletions Sources/AsyncAlgorithms/AsyncAlgorithms.docc/Guides/Lazy.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
Expand Down Expand Up @@ -66,4 +66,4 @@ public struct AsyncLazySequence<Base: Sequence>: AsyncSequence {
}
}

extension AsyncLazySequence: Sendable where Base: Sendable { }
extension AsyncSyncSequence: Sendable where Base: Sendable { }
14 changes: 7 additions & 7 deletions Tests/AsyncAlgorithmsTests/TestJoin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ 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
}
}

extension Sequence where Element: Sequence, Element.Element: Sendable {
var nestedAsync : AsyncLazySequence<[AsyncLazySequence<Element>]> {
var nestedAsync : AsyncSyncSequence<[AsyncSyncSequence<Element>]> {
return self.map { $0.async }.async
}
}
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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")
Expand Down