Example (Apple Official)
struct RangeError: Error {
}
let numbers = [-62, 1, 6, 10, 9, 22, 0, -1, 5]
let cancellable = numbers.publisher
.tryLast {
guard $0 != 0 else {throw RangeError()}
return true
}
.sink(
receiveCompletion: { print ("completion: \($0)", terminator: " ") },
receiveValue: { print ("\($0)", terminator: " ") }
)