Skip to content

Instantly share code, notes, and snippets.

@cocoahero
Last active September 20, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocoahero/38b160ec89f4beb0e29743d6e73a0a5c to your computer and use it in GitHub Desktop.
Save cocoahero/38b160ec89f4beb0e29743d6e73a0a5c to your computer and use it in GitHub Desktop.
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