Skip to content

Commit aed5422

Browse files
authored
AsyncLazySequence proposal (#189)
1 parent b6dff00 commit aed5422

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Evolution/NNNN-lazy.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# AsyncLazySequence
2+
3+
* Proposal: [NNNN](NNNN-lazy.md)
4+
* Authors: [Philippe Hausler](https://github.com/phausler)
5+
* Status: **Implemented**
6+
7+
* Implementation:
8+
[Source](https://github.com/apple/swift-async-algorithms/blob/main/Sources/AsyncAlgorithms/AsyncLazySequence.swift) |
9+
[Tests](https://github.com/apple/swift-async-algorithms/blob/main/Tests/AsyncAlgorithmsTests/TestLazy.swift)
10+
11+
## Introduction
12+
13+
`AsyncLazySequence` converts a non-asynchronous sequence into an asynchronous one.
14+
15+
This operation is available for all `Sequence` types.
16+
17+
```swift
18+
let numbers = [1, 2, 3, 4].async
19+
let characters = "abcde".async
20+
```
21+
22+
This transformation can be useful to test operations specifically available on `AsyncSequence` but also is useful
23+
to combine with other `AsyncSequence` types to provide well known sources of data.
24+
25+
The `.async` property returns an `AsyncLazySequence` that is generic upon the base `Sequence` it was constructed from.
26+
27+
```swift
28+
extension Sequence {
29+
public var async: AsyncLazySequence<Self> { get }
30+
}
31+
32+
public struct AsyncLazySequence<Base: Sequence>: AsyncSequence {
33+
...
34+
}
35+
36+
extension AsyncLazySequence: Sendable where Base: Sendable { }
37+
extension AsyncLazySequence.Iterator: Sendable where Base.Iterator: Sendable { }
38+
```
39+
40+
### Naming
41+
42+
This property's and type's name match the naming approaches in the Swift standard library. The property is named with a
43+
succinct name in inspiration from `.lazy`, and the type is named in reference to the lazy behavior of the constructed
44+
`AsyncSequence`.
45+
46+
## Effect on API resilience
47+
48+
`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.

0 commit comments

Comments
 (0)