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

103
Views
La mejor manera de implementar "Lo vi al menos una vez" en Combine

Necesito implementar algo como "ese valor en particular fue emitido por el editor al menos una vez en el pasado". Así que básicamente verdadero/falso. Como ejemplo para responder si alguna vez se envió cero aquí:

 let publisher = PassthroughSubject<Int, Never>() ... for _ in 1...3 { publisher.send(Int.random(in: 0...2)) }

Solo se me ocurrieron las siguientes opciones y ambas se sienten antinaturales de alguna manera:

 //Option #1 Using scan let hadZero = publisher .scan(false) { $0 || $1 == 0 } //Option #2 Merging with CurrentValueSubject let hadZero = Publishers.Merge( CurrentValueSubject<Bool, Never>(false), publisher.contains { $0 == 0 } )

¿Hay alguna manera mejor de hacerlo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede utilizar el operador contains , que emite true inmediatamente cuando el valor buscado es emitido por su upstream o emite false cuando upstream se completa sin haber emitido el valor buscado.

 let hadZero = publisher.contains(0)
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!