Created
June 20, 2017 05:12
-
-
Save Qata/b8323dce5eccffe56f467a7c2ba4f836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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