Skip to content

Instantly share code, notes, and snippets.

@Qata
Created June 20, 2017 05:12
Show Gist options
  • Save Qata/b8323dce5eccffe56f467a7c2ba4f836 to your computer and use it in GitHub Desktop.
Save Qata/b8323dce5eccffe56f467a7c2ba4f836 to your computer and use it in GitHub Desktop.
extension SignalProtocol where Value: OptionalProtocol {
func errorOnNil(_ error: Error) -> Signal<Value.Wrapped, Error> {
return attemptMap {
switch $0.optional {
case let unwrapped?:
return .success(unwrapped)
case nil:
return .failure(error)
}
}
}
}
extension SignalProducerProtocol where Value: OptionalProtocol {
func errorOnNil(_ error: Error) -> SignalProducer<Value.Wrapped, Error> {
return lift { $0.errorOnNil(error) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment