AnyPublisher

extension AnyPublisher where Output == Action

Available 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> to AnyPublisher<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 */ }
    

    Declaration

    Swift

    public func ofTypes<
        A1: Action,
        A2: Action
        >(_: A1.Type,
          _: A2.Type
    ) -> Publishers.CompactMap<Self, Action>
  • 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 */ }
    

    Declaration

    Swift

    public func ofTypes<
        A1: Action,
        A2: Action,
        A3: Action
        >(_: A1.Type,
          _: A2.Type,
          _: A3.Type
    ) -> Publishers.CompactMap<Self, Action>
  • 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 */ }
    

    Declaration

    Swift

    public func ofTypes<
        A1: Action,
        A2: Action,
        A3: Action,
        A4: Action
        >(_: A1.Type,
          _: A2.Type,
          _: A3.Type,
          _: A4.Type
    ) -> Publishers.CompactMap<Self, Action>
  • 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 */ }
    

    Declaration

    Swift

    public func ofTypes<
        A1: Action,
        A2: Action,
        A3: Action,
        A4: Action,
        A5: Action
        >(_: A1.Type,
          _: A2.Type,
          _: A3.Type,
          _: A4.Type,
          _: A5.Type
    ) -> Publishers.CompactMap<Self, Action>