Skip to content

Instantly share code, notes, and snippets.

@thexande
Created February 9, 2019 22:10
Show Gist options
  • Save thexande/41ff67dede676e5d6555dc2210641ed1 to your computer and use it in GitHub Desktop.
Save thexande/41ff67dede676e5d6555dc2210641ed1 to your computer and use it in GitHub Desktop.
`Result<T>` vs multi closure
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