Skip to content

Instantly share code, notes, and snippets.

@eMdOS
Last active May 2, 2020 02:35
Show Gist options
  • Save eMdOS/d869c0bb15f7e3f684e79e086b0699b5 to your computer and use it in GitHub Desktop.
Save eMdOS/d869c0bb15f7e3f684e79e086b0699b5 to your computer and use it in GitHub Desktop.
public extension Result where Success == (data: Data, response: URLResponse) {
func map<T>(_ keyPath: KeyPath<Success, T>) -> Result<T, Failure> {
switch self {
case .success(let response):
return .success(response[keyPath: keyPath])
case .failure(let error):
return .failure(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment