Publisher

public extension Publisher
extension Publisher where Output: SignalConvertible, Failure == Never
extension Publisher where Failure: DematerializationErrorConvertible
  • Wraps each element from the upstream publisher, as well as its subscription and completion events, into Signal values.

    Declaration

    Swift

    func materialize() -> Publishers.Materialize<Self>

    Return Value

    A publisher that wraps each element from the upstream publisher, as well as its subscription and completion events, into Signal values.

  • Returns a publisher as a class instance that replays previous values to new subscribers

    The downstream subscriber receives elements and completion states unchanged from the previous subscriber, and in addition replays the latest elements received from the upstream subscriber to any new subscribers. Use this operator when you want new subscribers to receive the most recently produced values immediately upon subscription.

    Declaration

    Swift

    public func share(replay maxBufferSize: Int) -> Publishers.ReferenceCounted<Self, ReplaySubject<Self.Output, Self.Failure>>

    Parameters

    maxBufferSize

    The number of elements that should be buffered for replay to new subscribers

    Return Value

    A class instance that republishes its upstream publisher and maintains a buffer of its latest values for replay to new subscribers

Operator

  • Marks points of interest for your publisher events as time intervals for debugging performance in Instruments.

    Declaration

    Swift

    func signpost(configuration: Publishers.SignpostConfiguration = .init(receiveMarker: .default)) -> Publishers.Signpost<Self>

    Parameters

    configuration

    A configuration value specifying which events to mark as points of interest. The default value specifies signposts should be grouped into the com.github.tcldr.Entwine.Signpost subsystem using the .pointsOfInterest category (displayed in most Xcode Intruments templates by default under the ‘Points of Interest’ instrument) . See Publishers.SignpostConfiguration initializer for detailed options.

    Return Value

    A publisher that marks points of interest when specified publisher events occur

  • Subscribes to an additional publisher and invokes a closure upon receiving output from this publisher.

    Declaration

    Swift

    func withLatest<T, P>(from other: P, transform: @escaping (Output, P.Output) -> T) -> Publishers.WithLatestFrom<Self, P, T> where P : Publisher, Self.Failure == P.Failure

    Parameters

    other

    Another publisher to combibe with this one

    transform

    A closure that receives each value produced by this publisher and the latest value from another publisher and returns a new value to publish

    Return Value

    A publisher that combines the latest value from another publisher with each value from this publisher

  • Subscribes to an additional publisher and produces its latest value each time this publisher produces a value.

    Declaration

    Swift

    func withLatest<P>(from other: P) -> Publishers.WithLatestFrom<Self, P, P.Output> where P : Publisher, Self.Failure == P.Failure

    Parameters

    other

    Another publisher to gather latest values from

    Return Value

    A publisher that produces the latest value from another publisher each time this publisher produces an element

Available where Output: SignalConvertible, Failure == Never

  • Converts a materialized upstream publisher of Signals into the represented sequence. Fails on a malformed source sequence.

    Use this operator to convert a stream of Signal values from an upstream publisher into its materially represented publisher type. Malformed sequences will fail with a DematerializationError.

    For each element:

    • .subscription elements are ignored
    • .input(_) elements are unwrapped and forwarded to the subscriber
    • .completion(_) elements are forwarded within the DematerializationError wrapper

    If the integrity of the upstream sequence can be guaranteed, use the assertNoDematerializationFailure() operator immediately following this one to force unwrap any errors and produce a publisher with a Failure type that matches the materially represented original sequence.

    Declaration

    Swift

    public func dematerialize() -> Publishers.FlatMap<AnyPublisher<Self.Output.Input, DematerializationError<Self.Output.Failure>>, Publishers.Dematerialize<Self>>

    Return Value

    A publisher that materializes an upstream publisher of Signals into the represented sequence.

Available where Failure: DematerializationErrorConvertible

  • Force unwraps the errors of a dematerialized publisher to return a publisher that matches that of the materially represented original sequence

    When using the dematerialize() operator the publisher returned has a Failure type of DematerializationError to account for the possibility of a malformed Signal sequence.

    If the integrity of the upstream sequence can be guaranteed, use this operator to force unwrap the errors to produce a publisher with a Failure type that matches the materially represented original sequence.

    Declaration

    Swift

    public func assertNoDematerializationFailure() -> Publishers.MapError<Self, Failure.SourceError>

    Return Value

    A publisher with a Failure type that matches that of the materially represented original sequence