How to convert Just<[Int]>
to AnyPublisher<[Int], Error>
. When I use eraseToAnyPublisher()
the type is AnyPublisher<[Int], Never>
which is not the same as AnyPublisher<[Int], Error>
For example I have a simple function which I want to mock temporary
func getAllIds() -> AnyPublisher<[Int], Error> {
return Just<[Int]>([]).eraseToAnyPublisher()
}
Any ideas?
AnyPublisher is a concrete implementation of Publisher that has no significant properties of its own, and passes through elements and completion values from its upstream publisher. Use AnyPublisher to wrap a publisher whose type has details you don't want to expose across API boundaries, such as different modules.
A publisher that emits an output to each subscriber just once, and then finishes.
Overview. The Combine framework provides a declarative Swift API for processing values over time. These values can represent many kinds of asynchronous events. Combine declares publishers to expose values that can change over time, and subscribers to receive those values from the publishers.
Use .setFailureType
. The situation you are in is exactly what it is for:
Just([Int]())
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With