I have two Signals from Notifications. These where fired from an external framework.
let successSignal = NotificationCenter.default.reactive.notifications(forName: NSNotification.Name(rawValue: "someNotification"))
let failedSignal = NotificationCenter.default.reactive.notifications(forName: NSNotification.Name(rawValue: "someNotification"))
Now I want to combine them to one signal of type Signal<Notification, Error>.
If successSignal fires send Value, if failedSinal fires send Error.
I have no idea how to manage this.
Here's a way to do this:
For this new signal, a value on the
failedSignalwill be turned into anerrorEvent, sofailingFailedis a Signal on which events onfailedSignalnow arrive as.failedinstead of.value.Keep the Event Stream Grammar in mind - after one
.failedevent, the Signal terminates!Then we merge the
successSignalandfailingFailedsignal together. Since a.failedevent behaves like an exception and propagates immediately, the whole merged signal will also fail immediately when a.failedevent arrives onfailingFailed.The
promoteErroronsuccessSignalis necessary for type checking reasons.