Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

80
Views
Generic requirement that Some: AsyncSequence is not throwing

I would like to extend AsyncSequence in ways that depend on whether the sequence can throw. Neither AsyncSequence nor AsyncIteratorProtocol distinguish such sequences explicitly. Yet, the concurrency module does come with concrete sequences with throwing and non-throwing variants. The only generic difference I see is that the next method of non-throwing sequences are rethrowing. Here is an example:

extension AsyncMapSequence : AsyncSequence {

    struct Iterator : AsyncIteratorProtocol {

        mutating func next() async rethrows -> Transformed?
    }
}

Whereas the throwing variant is a plain throws:

extension AsyncThrowingMapSequence : AsyncSequence {

    struct Iterator : AsyncIteratorProtocol {

        mutating func next() async throws -> Transformed?
    }
}

(I am not even sure how rethrows is even possible for a method that does not take any arguments. The only thing that comes to mind is that the curried expression of such a method could throw some light on that...)

So, the question is how to express something along the lines of:

extension AsyncSequence where AsyncIterator /* is not throwing */ {

}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When this proposal is fully implemented you will be able to express conformance to a failable sequence by providing some syntax sugar

extension AsyncSequence where nothrow AsyncIterator {

or

struct Foo<S: nothrow AsyncSequence>

This comes from the @rethrows annotation currently attached to AsyncSequence

@rethrows public protocol AsyncSequence
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!