Primary Associated Types for AsyncSequences

Can't speak to the official introduction, but you have a workaround available by defining this protocol in your project today:

public protocol ATAsyncSequence<Element>: AsyncSequence { }

and extend whatever concrete sequence types you use to conform to ATAsyncSequence:

extension AsyncCompactMapSequence: ATAsyncSequence { }
extension AsyncFilterSequence: ATAsyncSequence { }
extension AsyncFlatMapSequence: ATAsyncSequence { }
...

Once you have that in your project you can use ATAsyncSequence wherever you needed the specificity:

func collectZeros(_ input: some ATAsyncSequence<Int>) -> some ATAsyncSequence<Int> {
    return input.filter { $0 == 0 }
}
4 Likes