example(of: "last(where:)") {
enum MyError: Error {
case test
}
let subject = PassthroughSubject<Int, MyError>()
subject
.eraseToAnyPublisher()
.last(where: { $0 % 2 == 0 })
.sink(receiveCompletion: { print("Completed with: ", $0) },
receiveValue: { print($0) })
.store(in: &subscriptions)
subject.send(1)
subject.send(2)
subject.send(4)
subject.send(completion: .failure(MyError.test))
}
Output:
——— Example of: last(where:) 2 ———
Completed with: failure(...).MyError.test)
How can I receive the value 4
?