Signal

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public enum Signal<Input, Failure> where Failure : Error
extension Signal: SignalConvertible
extension Signal: Equatable where Input: Equatable, Failure: Equatable

A materialized representation of a Publishers output.

Upon a call to subscribe, a legal Publisher produces signals in strictly the following order:

  • Exactly one ‘subscription’ signal.
  • Followed by zero or more ‘input’ signals.
  • Terminated finally by a single ‘completion’ signal.
  • Sent by a Publisher to a Subscriber in acknowledgment of the Subscriber‘s subscription request.

    Declaration

    Swift

    case subscription
  • The payload of a subscription. Zero to many .input(_) signals may be produced during the lifetime of a Subscriber‘s subscription to a Publisher.

    Declaration

    Swift

    case input(Input)
  • The final signal sent to a Subscriber during a subscription to a Publisher. Indicates termination of the stream as well as the reason.

    Declaration

    Swift

    case completion(Subscribers.Completion<Failure>)

Signal extensions

  • Whether the signal indicates sequence completion

    Declaration

    Swift

    var isCompletion: Bool { get }
  • Returns a signal with a transformed input type and input element

    Declaration

    Swift

    func mapInput<T>(_ transform: (Input) -> T) -> Signal<T, Failure>

    Parameters

    transform

    A mapping closure. transform accepts an element of this signal’s input type as its parameter and returns a transformed value of the same or of a different type.

    Return Value

    A signal with a transformed input type and input element

  • Returns a signal with a transformed failure type and completion element

    Declaration

    Swift

    func mapFailure<T>(_ transform: (Failure) -> T) -> Signal<Input, T> where T : Error

    Parameters

    transform

    A mapping closure. transform accepts an element of this signal’s failure type as its parameter and returns a transformed error of the same or of a different type.

    Return Value

    A signal with a transformed failure type and completion element

Equatable conformance

  • Declaration

    Swift

    public var signal: Signal<Input, Failure> { get }

Available where Input: Equatable, Failure: Equatable

  • Declaration

    Swift

    public static func == (lhs: Signal<Input, Failure>, rhs: Signal<Input, Failure>) -> Bool