我想以AsyncSequence取决于序列是否可以抛出的方式进行扩展。既不AsyncSequence明确AsyncIteratorProtocol区分这些序列。然而,并发模块确实带有带有抛出和非抛出变体的具体序列。我看到的唯一一般区别next是非抛出序列的方法是重新抛出。这是一个例子:
extension AsyncMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async rethrows -> Transformed?
}
}
Run Code Online (Sandbox Code Playgroud)
而投掷变体是一个简单的throws:
extension AsyncThrowingMapSequence : AsyncSequence {
struct Iterator : AsyncIteratorProtocol {
mutating func next() async throws -> Transformed?
}
}
Run Code Online (Sandbox Code Playgroud)
(我什至不确定rethrows一个不带任何参数的方法如何可能。唯一想到的是这种方法的柯里化表达式可以对此有所启发...... )
因此,问题是如何表达以下内容:
extension AsyncSequence where AsyncIterator /* is not throwing */ {
}
Run Code Online (Sandbox Code Playgroud)
当这个提案完全实现时,您将能够通过提供一些语法糖来表达对可失败序列的一致性
extension AsyncSequence where nothrow AsyncIterator {
Run Code Online (Sandbox Code Playgroud)
或者
struct Foo<S: nothrow AsyncSequence>
Run Code Online (Sandbox Code Playgroud)
这来自@rethrows当前附加的注释AsyncSequence
@rethrows public protocol AsyncSequence
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
432 次 |
| 最近记录: |