Publisher
extension Publisher where Self.Output : Action
-
Wraps this publisher with a type eraser to return a generic
Action
protocol.Use to expose a generic
Action
, rather than this publisher’s actual Action implementer. This will help satisfy constraints for Publishers that are expected to be of typeAction
.// Below: Error: Cannot convert value of type 'AnyPublisher<GetPost, Never>' to specified type 'AnyPublisher<Action, Never>' let actionPublisher: AnyPublisher<Action, Never> = actions .ofType(GetPost.self) .handleEvents(receiveOutput: { _ in print("Got it") }) .eraseToAnyPublisher() // Below: No error with eraseActionType() let actionPublisher: AnyPublisher<Action, Never> = actions .ofType(GetPost.self) .handleEvents(receiveOutput: { _ in print("Got it") }) .eraseActionType() .eraseToAnyPublisher()
Declaration
Swift
public func eraseActionType() -> Publishers.Map<Self, Action>