Last active
September 20, 2017 19:44
-
-
Save cocoahero/38b160ec89f4beb0e29743d6e73a0a5c to your computer and use it in GitHub Desktop.
This file contains 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 SignalProducer where Value == (Data, URLResponse), Error == AnyError { | |
func jsonDecode<T: Decodable>(decoder: JSONDecoder = JSONDecoder()) -> SignalProducer<T, AnyError> { | |
return attemptMap({ data, _ in | |
try decoder.decode(T.self, from: data) | |
}) | |
} | |
} | |
extension SignalProducer where Value: Encodable, Error == AnyError { | |
func jsonEncode(encoder: JSONEncoder = JSONEncoder()) -> SignalProducer<Data, AnyError> { | |
return attemptMap({ value in | |
try encoder.encode(value) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment