Skip to content

Instantly share code, notes, and snippets.

Created Apr 7, 2020
What would you like to do?
Example `Result.Publisher` usage.
import Combine
import PlaygroundSupport
enum SomeError: Error {
case anError
func someThrowingFunction() throws {
guard Bool.random() else { throw SomeError.anError } /// For sake of example, `throw` on `false` values.
var subscriptions = Set<AnyCancellable>()
Result { try someThrowingFunction() }
receiveCompletion: { completion in
switch completion {
case .finished:
case .failure:
print("`someThrowingFunction` threw.")
receiveValue: { print("`someThrowingFunction` didn’t error.") }
.store(in: &subscriptions)
PlaygroundPage.current.needsIndefiniteExecution = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment