Last active
June 3, 2018 20:43
-
-
Save guidomb/57b8ac391dfeb0514c9ae872b6574175 to your computer and use it in GitHub Desktop.
Swift 4.2 regression
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
import Foundation | |
struct AnyError: Error { | |
private let error: Error | |
init(_ error: Error) { | |
self.error = error | |
} | |
} | |
enum Result<T, E: Error> { | |
case success(T) | |
case failure(E) | |
func mapError<NewError: Error>(_ transform: (E) -> NewError) -> Result<T, NewError> { | |
switch self { | |
case .success(let value): | |
return .success(value) | |
case .failure(let error): | |
return .failure(transform(error)) | |
} | |
} | |
} | |
protocol Service { | |
func execute<T>() -> Result<T, AnyError> | |
} | |
struct Foo { | |
enum Bar: Error { | |
case foo | |
case bar(Error) | |
} | |
} | |
final class Baz { | |
func someFunction<T>(service: Service) -> Result<T, Foo.Bar> { | |
return service.execute().mapError(Foo.Bar.bar) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment