Created
February 20, 2015 15:09
-
-
Save hborders/61c24cc77ff3c5d7ba34 to your computer and use it in GitHub Desktop.
Is there a better way to handle the failure case?
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
class Box<A> { | |
public let value: A | |
init(_ value: A) { self.value = value } | |
} | |
enum Result<A> { | |
case Success(Box<A>) | |
case Failure(NSError) | |
} | |
class Fizz { | |
} | |
class Buzz { | |
} | |
class Foo { | |
func foo() -> Result<Fizz> { | |
let result = // a result | |
return result | |
} | |
} | |
class Bar { | |
func bar(foo: Foo) -> Result<Buzz> { | |
switch foo.foo() { | |
case .Success(let fizzBox): | |
let buzz = // a buzz | |
return .Success(Box(buzz)) | |
// There must be a swiftier way to handle the failure case! | |
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
https://twitter.com/cocoaphony/status/568791893917732865