I'd like to create a repeat functionality that creates a loop in my code using Combine. I noticed that Combine does not have a repeat publisher via this great repo: https://github.com/freak4pc/rxswift-to-combine-cheatsheet. Heres the code that I wrote that works to repeat 2 states. How do I reduce this to something more readable or create my own repeat function?
toggleShouldDisplay = Just<Void>(())
.delay(for: 2, scheduler:RunLoop.main)
.map({ _ in
self.shouldDisplay = true
self.didChange.send(())
})
.delay(for: 2, scheduler: RunLoop.main)
.map({ _ in
self.shouldDisplay = false
self.didChange.send(())
})
.setFailureType(to: NSError.self)
.tryMap({ _ in
throw NSError()
})
.retry(.max) // I might hit Int.max if I reduce the delays
.sink(receiveValue: { _ in
//Left empty
})