Skip to content

Instantly share code, notes, and snippets.

@erikbasargin
Last active July 9, 2019 20:52
Show Gist options
  • Save erikbasargin/1c2820237761e6dee2641cfd78a320a1 to your computer and use it in GitHub Desktop.
Save erikbasargin/1c2820237761e6dee2641cfd78a320a1 to your computer and use it in GitHub Desktop.
Fix Publisher.decode for JSONDecoder and TopLevelDecoder πŸ› 
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Publisher where Output == URLSession.DataTaskPublisher.Output {
public func decode<Item, Coder>(type: Item.Type, decoder: Coder) -> Publishers.TryMap<Self, Item> where Item: Decodable, Coder: TopLevelDecoder, Coder.Input == Data {
return tryMap { try decoder.decode(type, from: $0.data) }
}
}
@erikbasargin
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment