Created
February 9, 2019 22:10
-
-
Save thexande/41ff67dede676e5d6555dc2210641ed1 to your computer and use it in GitHub Desktop.
`Result<T>` vs multi closure
This file contains hidden or 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
enum Result<T, Error> { | |
case success(T) | |
case failure(Error) | |
} | |
func resultCallback(completion: @escaping((Result<Int, Error>) -> Void)) { | |
} | |
func multiCompletionCallback(success: ((Int) -> Void)?, | |
error: ((Error) -> Void)?) { | |
} | |
resultCallback { result in | |
switch result { | |
case let .success(n): | |
print(n) | |
case let .failure(error): | |
print(error) | |
} | |
} | |
multiCompletionCallback(success: { n in | |
print(n) | |
}) { e in | |
print(e) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment