Instance Method

eraseToAnyPublisher()

Wraps this publisher with a type eraser.

Declaration

func eraseToAnyPublisher() -> AnyPublisher<Self.Output, Self.Failure>

Return Value

An AnyPublisher wrapping this publisher.

Discussion

Use eraseToAnyPublisher() to expose an instance of AnyPublisher to the downstream subscriber, rather than this publisher’s actual type. This form of type erasure preserves abstraction across API boundaries, such as different modules. When you expose your publishers as the AnyPublisher type, you can change the underlying implementation over time without affecting existing clients.