Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Hole<T> {
- static var value: T {
- fatalError("Unfilled hole of type `\(String(describing: T.self))`")
- }
- }
- enum Result<T, E: Error> {
- case success(T)
- case failure(E)
- func map<U>(_ tranform: (T) -> U) -> Result<U, E> {
- switch self {
- case let .success(value):
- return .success(tranform(value))
- case let .failure(error):
- return .failure(error)
- }
- }
- }
- func getResult() -> Result<String, NSError> {
- return Result
- .success(3)
- .map { value in
- Hole.value // quick help shows you need to return String
- }
- }
- getResult() // fatal error: Unfilled hole of type `String`
- // Could also use a free function, but quick help isn't quite as nice since it shows a function signature instead of the exact type
- func hole<T>() -> T {
- fatalError("Unfilled hole of type `\(String(describing: T.self))`")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement