AnyPublisher
extension AnyPublisher where Output == Action
-
Filter that includes only the
Action
type that is given, and maps to that specific Action type.The code block converts the action stream from
AnyPublisher<Action, Never>
toAnyPublisher<GetPost, Never>
:let getPostOnly: AnyPublisher<GetPost, Never> = actions .ofType(GetPost.self) .eraseToAnyPublisher()
Declaration
Swift
public func ofType<A>(_: A.Type) -> Publishers.CompactMap<`Self`, A> where A : Action
-
Filter that includes only the two
Action
types that are given.actions .ofType(Action1.self, Action2.self) .map { action in /* action will be of type Action1 or Action2 */ }
-
Filter that includes only the three
Action
types that are given.actions .ofType(Action1.self, Action2.self, Action3.self) .map { action in /* action will be of type Action1, Action2, or Action3 */ }
-
Filter that includes only the four
Action
types that are given.actions .ofType(Action1.self, Action2.self, Action3.self, Action4.self) .map { action in /* action will be of type Action1, Action2, Action3, or Action4 */ }
-
Filter that includes only the five
Action
types that are given.actions .ofType(Action1.self, Action2.self, Action3.self, Action4.self, Action5.self) .map { action in /* action will be of type Action1, Action2, Action3, Action4, or Action5 */ }