Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

82
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda