AnyPublisher

public extension AnyPublisher
  • Helper for returning a Just publisher, with the appropriate Failure type and erased to AnyPublisher

    Declaration

    Swift

    static func just(_ output: Output) -> AnyPublisher<Output, Failure>
  • Helper for returning a Fail publisher, erased to AnyPublisher

    Declaration

    Swift

    static func fail(with error: Failure) -> AnyPublisher<Output, Failure>
  • Call .handleEvents, but only use the receiveOutput callback as a shorthand way of running some logic or clean up code

    Declaration

    Swift

    func onReceiveOutput(_ callback: @escaping ((`Self`.Output) -> Void)) -> Publishers.HandleEvents<`Self`>
  • Custom sink implementation breaking each piece into a seperate dedicated callback, avoiding the need to call a switch or unwrap an error

    Declaration

    Swift

    func sink(onError: @escaping ((Failure) -> Void), onSuccess: @escaping ((Output) -> Void), onComplete: (() -> Void)? = nil) -> AnyCancellable