Skip to content

Instantly share code, notes, and snippets.

@Zedd0202
Created June 14, 2020 06:11
struct IllegalValueError: Error {}
let numbers: [Int] = [0, 10, 6, 13, 22, 22]
numbers.publisher
.tryMin { first, second -> Bool in
if (first % 2 != 0) {
throw IllegalValueError()
}
return first < second
}
.sink(
receiveCompletion: { print ("completion: \($0)") },
receiveValue: { print ("value: \($0)") }
)
// Prints: "completion: failure(IllegalValueError())"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment