Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

79
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda