SignalProducer

public struct SignalProducer<Value, Error> where Error : Error

A SignalProducer creates Signals that can produce values of type Value and/or fail with errors of type Error. If no failure should be possible, NoError can be specified for Error.

SignalProducers can be used to represent operations or tasks, like network requests, where each invocation of start() will create a new underlying operation. This ensures that consumers will receive the results, versus a plain Signal, where the results might be sent before any observers are attached.

Because of the behavior of start(), different Signals created from the producer may see a different version of Events. The Events may arrive in a different order between Signals, or the stream might be completely different!

  • Convert an entity into its equivalent representation as SignalProducer.

    Declaration

    Swift

    public init<T>(_ base: T) where Value == T.Value, Error == T.Error, T : SignalProducerConvertible

    Parameters

    base

    The entity to convert from.

  • Initializes a SignalProducer that will emit the same events as the given signal.

    If the Disposable returned from start() is disposed or a terminating event is sent to the observer, the given signal will be disposed.

    Declaration

    Swift

    public init(_ signal: Signal<Value, Error>)

    Parameters

    signal

    A signal to observe after starting the producer.

  • Initialize a SignalProducer which invokes the supplied starting side effect once upon the creation of every produced Signal, or in other words, for every invocation of startWithSignal(_:), start(_:) and their convenience shorthands.

    The supplied starting side effect would be given (1) an input Observer to emit events to the produced Signal; and (2) a Lifetime to bind resources to the lifetime of the produced Signal.

    The Lifetime of a produced Signal ends when: (1) a terminal event is sent to the input Observer; or (2) when the produced Signal is interrupted via the disposable yielded at the starting call.

    Declaration

    Swift

    public init(_ startHandler: @escaping (Signal<Value, Error>.Observer, Lifetime) -> Void)

    Parameters

    startHandler

    The starting side effect.

  • Creates a producer for a Signal that will immediately send one value then complete.

    Declaration

    Swift

    public init(value: Value)

    Parameters

    value

    A value that should be sent by the Signal in a value event.

  • Creates a producer for a Signal that immediately sends one value, then completes.

    This initializer differs from init(value:) in that its sole value event is constructed lazily by invoking the supplied action when the SignalProducer is started.

    Declaration

    Swift

    public init(_ action: @escaping () -> Value)

    Parameters

    action

    A action that yields a value to be sent by the Signal as a value event.

  • Create a SignalProducer that will attempt the given operation once for each invocation of start().

    Upon success, the started signal will send the resulting value then complete. Upon failure, the started signal will fail with the error that occurred.

    Declaration

    Swift

    public init(_ action: @escaping () -> Result<Value, Error>)

    Parameters

    action

    A closure that returns instance of Result.

  • Creates a producer for a Signal that will immediately fail with the given error.

    Declaration

    Swift

    public init(error: Error)

    Parameters

    error

    An error that should be sent by the Signal in a failed event.

  • Creates a producer for a Signal that will immediately send one value then complete, or immediately fail, depending on the given Result.

    Declaration

    Swift

    public init(result: Result<Value, Error>)

    Parameters

    result

    A Result instance that will send either value event if result is successful or failed event if result is a failure.

  • Creates a producer for a Signal that will immediately send the values from the given sequence, then complete.

    Declaration

    Swift

    public init<S>(_ values: S) where Value == S.Element, S : Sequence

    Parameters

    values

    A sequence of values that a Signal will send as separate value events and then complete.

  • Creates a producer for a Signal that will immediately send the values from the given sequence, then complete.

    Declaration

    Swift

    public init(values first: Value, _ second: Value, _ tail: Value...)

    Parameters

    first

    First value for the Signal to send.

    second

    Second value for the Signal to send.

    tail

    Rest of the values to be sent by the Signal.

  • A producer for a Signal that immediately completes without sending any values.

    Declaration

    Swift

    public static var empty: SignalProducer { get }
  • A producer for a Signal that never sends any events to its observers.

    Declaration

    Swift

    public static var never: SignalProducer { get }
  • Create a Signal from self, pass it into the given closure, and start the associated work on the produced Signal as the closure returns.

    Declaration

    Swift

    @discardableResult
    public func startWithSignal<Result>(_ setup: (_ signal: Signal<Value, Error>, _ interruptHandle: Disposable) -> Result) -> Result

    Parameters

    setup

    A closure to be invoked before the work associated with the produced Signal commences. Both the produced Signal and an interrupt handle of the signal would be passed to the closure.

    Return Value

    The return value of the given setup closure.

  • Logs all events that the receiver sends. By default, it will print to the standard output.

    Declaration

    Swift

    public func logEvents(identifier: String = "",
                          events: Set<LoggingEvent.SignalProducer> = LoggingEvent.SignalProducer.allEvents,
                          fileName: String = #file,
                          functionName: String = #function,
                          lineNumber: Int = #line,
                          logger: @escaping EventLogger = defaultEventLog
    ) -> SignalProducer<Value, Error>

    Parameters

    identifier

    a string to identify the SignalProducer firing events.

    events

    Types of events to log.

    fileName

    Name of the file containing the code which fired the event.

    functionName

    Function where event was fired.

    lineNumber

    Line number where event was fired.

    logger

    Logger that logs the events.

    Return Value

    Signal producer that, when started, logs the fired events.

  • Flattens the inner producers sent upon producer (into a single producer of values), according to the semantics of the given strategy.

    Note

    If producer or an active inner producer fails, the returned producer will forward that failure immediately.

    Warning

    interrupted events on inner producers will be treated like completed events on inner producers.

    Declaration

    Swift

    public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Error>

    Parameters

    strategy

    Strategy used when flattening signals.

  • Flattens the inner producers sent upon producer (into a single producer of values), according to the semantics of the given strategy.

    Note

    If an active inner producer fails, the returned producer will forward that failure immediately.

    Warning

    interrupted events on inner producers will be treated like completed events on inner producers.

    Declaration

    Swift

    public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Value.Error>

    Parameters

    strategy

    Strategy used when flattening signals.

  • Flattens the inner producers sent upon producer (into a single producer of values), according to the semantics of the given strategy.

    Warning

    interrupted events on inner producers will be treated like completed events on inner producers.

    Declaration

    Swift

    public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Value.Error>

    Parameters

    strategy

    Strategy used when flattening signals.

  • Flattens the inner producers sent upon signal (into a single signal of values), according to the semantics of the given strategy.

    Note

    If signal fails, the returned signal will forward that failure immediately.

    Warning

    interrupted events on inner producers will be treated like completed events on inner producers.

    Declaration

    Swift

    public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Error>

    Parameters

    strategy

    Strategy used when flattening signals.

  • Flattens the sequence value sent by signal.

    Declaration

    Swift

    public func flatten() -> SignalProducer<Value.Iterator.Element, Error>
  • concats next onto self.

    Declaration

    Swift

    public func concat(_ next: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>

    Parameters

    next

    A follow-up producer to concat self with.

    Return Value

    A producer that will start self and then on completion of self - will start next.

  • concats next onto self.

    Declaration

    Swift

    public func concat<Next>(_ next: Next) -> SignalProducer<Value, Error> where Value == Next.Value, Error == Next.Error, Next : SignalProducerConvertible

    Parameters

    next

    A follow-up producer to concat self with.

    Return Value

    A producer that will start self and then on completion of self - will start next.

  • concats value onto self.

    Declaration

    Swift

    public func concat(value: Value) -> SignalProducer<Value, Error>

    Parameters

    value

    A value to concat onto self.

    Return Value

    A producer that, when started, will emit own values and on completion will emit a value.

  • concats error onto self.

    Declaration

    Swift

    public func concat(error: Error) -> SignalProducer<Value, Error>

    Parameters

    error

    An error to concat onto self.

    Return Value

    A producer that, when started, will emit own values and on completion will emit an error.

  • concats self onto initial previous.

    Declaration

    Swift

    public func prefix(_ previous: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>

    Parameters

    previous

    A producer to start before self.

    Return Value

    A signal producer that, when started, first emits values from previous producer and then from self.

  • concats self onto initial previous.

    Declaration

    Swift

    public func prefix<Previous>(_ previous: Previous) -> SignalProducer<Value, Error> where Value == Previous.Value, Error == Previous.Error, Previous : SignalProducerConvertible

    Parameters

    previous

    A producer to start before self.

    Return Value

    A signal producer that, when started, first emits values from previous producer and then from self.

  • concats self onto initial value.

    Declaration

    Swift

    public func prefix(value: Value) -> SignalProducer<Value, Error>

    Parameters

    value

    A first value to emit.

    Return Value

    A producer that, when started, first emits value, then all values emited by self.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Warning

    If self or any of the created producers fail, the returned producer will forward that failure immediately.

    Declaration

    Swift

    public func flatMap<U>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> SignalProducer<U, Error>) -> SignalProducer<U, Error>

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Warning

    If self or any of the created producers fail, the returned producer will forward that failure immediately.

    Declaration

    Swift

    public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Error> where Inner.Error == Error

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Warning

    If self fails, the returned producer will forward that failure immediately.

    Declaration

    Swift

    public func flatMap<U>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> SignalProducer<U, NoError>) -> SignalProducer<U, Error>

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Warning

    If self fails, the returned producer will forward that failure immediately.

    Declaration

    Swift

    public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Error> where Inner.Error == NoError

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Declaration

    Swift

    public func flatMap<U>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> SignalProducer<U, Error>) -> SignalProducer<U, Error>

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Declaration

    Swift

    public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Error> where Inner.Error == Error

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Warning

    If any of the created producers fail, the returned producer will forward that failure immediately.

    Declaration

    Swift

    public func flatMap<U, F>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> SignalProducer<U, F>) -> SignalProducer<U, F>

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Maps each event from self to a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.

    Warning

    If any of the created producers fail, the returned producer will forward that failure immediately.

    Declaration

    Swift

    public func flatMap<Inner: SignalProducerConvertible>(_ strategy: FlattenStrategy, _ transform: @escaping (Value) -> Inner) -> SignalProducer<Inner.Value, Inner.Error>

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

    A closure that takes a value emitted by self and returns a signal producer with transformed value.

  • Catches any failure that may occur on the input producer, mapping to a new producer that starts in its place.

    Declaration

    Swift

    public func flatMapError<F>(_ transform: @escaping (Error) -> SignalProducer<Value, F>) -> SignalProducer<Value, F>

    Parameters

    transform

    A closure that accepts emitted error and returns a signal producer with a different type of error.

  • Catches any failure that may occur on the input producer, mapping to a new producer that starts in its place.

    Declaration

    Swift

    public func flatMapError<Inner: SignalProducerConvertible>(_ transform: @escaping (Error) -> Inner) -> SignalProducer<Value, Inner.Error> where Inner.Value == Value

    Parameters

    transform

    A closure that accepts emitted error and returns a signal producer with a different type of error.

  • Creates a producer for a Signal that will immediately send one value then complete.

    Declaration

    Swift

    public init(value: Value)

    Parameters

    value

    A value that should be sent by the Signal in a value event.

  • Creates a producer for a Signal that will immediately send the values from the given sequence, then complete.

    Declaration

    Swift

    public init<S>(_ values: S) where Value == S.Element, S : Sequence

    Parameters

    values

    A sequence of values that a Signal will send as separate value events and then complete.

  • Creates a producer for a Signal that will immediately send the values from the given sequence, then complete.

    Declaration

    Swift

    public init(values first: Value, _ second: Value, _ tail: Value...)

    Parameters

    first

    First value for the Signal to send.

    second

    Second value for the Signal to send.

    tail

    Rest of the values to be sent by the Signal.

  • Create a SignalProducer that will attempt the given failable operation once for each invocation of start().

    Upon success, the started producer will send the resulting value then complete. Upon failure, the started signal will fail with the error that occurred.

    Declaration

    Swift

    public init(_ action: @escaping () throws -> Value)

    Parameters

    operation

    A failable closure.

  • Declaration

    Swift

    public var producer: SignalProducer { get }
  • Create a Signal from self, and observe it with the given observer.

    Declaration

    Swift

    @discardableResult
    public func start(_ observer: Signal<Value, Error>.Observer = .init()) -> Disposable

    Parameters

    observer

    An observer to attach to the produced Signal.

    Return Value

    A disposable to interrupt the produced Signal.

  • Create a Signal from self, and observe the Signal for all events being emitted.

    Declaration

    Swift

    @discardableResult
    public func start(_ action: @escaping Signal<Value, Error>.Observer.Action) -> Disposable

    Parameters

    action

    A closure to be invoked with every event from self.

    Return Value

    A disposable to interrupt the produced Signal.

  • Create a Signal from self, and observe the Signal for all values being emitted, and if any, its failure.

    Declaration

    Swift

    @discardableResult
    public func startWithResult(_ action: @escaping (Result<Value, Error>) -> Void) -> Disposable

    Parameters

    action

    A closure to be invoked with values from self, or the propagated error should any failed event is emitted.

    Return Value

    A disposable to interrupt the produced Signal.

  • Create a Signal from self, and observe its completion.

    Declaration

    Swift

    @discardableResult
    public func startWithCompleted(_ action: @escaping () -> Void) -> Disposable

    Parameters

    action

    A closure to be invoked when a completed event is emitted.

    Return Value

    A disposable to interrupt the produced Signal.

  • Create a Signal from self, and observe its failure.

    Declaration

    Swift

    @discardableResult
    public func startWithFailed(_ action: @escaping (Error) -> Void) -> Disposable

    Parameters

    action

    A closure to be invoked with the propagated error, should any failed event is emitted.

    Return Value

    A disposable to interrupt the produced Signal.

  • Create a Signal from self, and observe its interruption.

    Declaration

    Swift

    @discardableResult
    public func startWithInterrupted(_ action: @escaping () -> Void) -> Disposable

    Parameters

    action

    A closure to be invoked when an interrupted event is emitted.

    Return Value

    A disposable to interrupt the produced Signal.

  • Create a Signal from self, and observe the Signal for all values being emitted.

    Declaration

    Swift

    @discardableResult
    public func startWithValues(_ action: @escaping (Value) -> Void) -> Disposable

    Parameters

    action

    A closure to be invoked with values from the produced Signal.

    Return Value

    A disposable to interrupt the produced Signal.

  • Lift an unary Signal operator to operate upon SignalProducers instead.

    In other words, this will create a new SignalProducer which will apply the given Signal operator to every created Signal, just as if the operator had been applied to each Signal yielded from start().

    Declaration

    Swift

    public func lift<U, F>(_ transform: @escaping (Signal<Value, Error>) -> Signal<U, F>) -> SignalProducer<U, F>

    Parameters

    transform

    An unary operator to lift.

    Return Value

    A signal producer that applies signal’s operator to every created signal.

  • Lift a binary Signal operator to operate upon SignalProducers instead.

    In other words, this will create a new SignalProducer which will apply the given Signal operator to every Signal created from the two producers, just as if the operator had been applied to each Signal yielded from start().

    Note

    starting the returned producer will start the receiver of the operator, which may not be adviseable for some operators.

    Declaration

    Swift

    public func lift<U, F, V, G>(_ transform: @escaping (Signal<Value, Error>) -> (Signal<U, F>) -> Signal<V, G>) -> (SignalProducer<U, F>) -> SignalProducer<V, G>

    Parameters

    transform

    A binary operator to lift.

    Return Value

    A binary operator that operates on two signal producers.

  • Map each value in the producer to a new value.

    Declaration

    Swift

    public func map<U>(_ transform: @escaping (Value) -> U) -> SignalProducer<U, Error>

    Parameters

    transform

    A closure that accepts a value and returns a different value.

    Return Value

    A signal producer that, when started, will send a mapped value of self.

  • Map each value in the producer to a new constant value.

    Declaration

    Swift

    public func map<U>(value: U) -> SignalProducer<U, Error>

    Parameters

    value

    A new value.

    Return Value

    A signal producer that, when started, will send a mapped value of self.

  • Map each value in the producer to a new value by applying a key path.

    Declaration

    Swift

    public func map<U>(_ keyPath: KeyPath<Value, U>) -> SignalProducer<U, Error>

    Parameters

    keyPath

    A key path relative to the producer’s Value type.

    Return Value

    A producer that will send new values.

  • Map errors in the producer to a new error.

    Declaration

    Swift

    public func mapError<F>(_ transform: @escaping (Error) -> F) -> SignalProducer<Value, F>

    Parameters

    transform

    A closure that accepts an error object and returns a different error.

    Return Value

    A producer that emits errors of new type.

  • Maps each value in the producer to a new value, lazily evaluating the supplied transformation on the specified scheduler.

    Important

    Unlike map, there is not a 1-1 mapping between incoming values, and values sent on the returned producer. If scheduler has not yet scheduled transform for execution, then each new value will replace the last one as the parameter to transform once it is finally executed.

    Declaration

    Swift

    public func lazyMap<U>(on scheduler: Scheduler, transform: @escaping (Value) -> U) -> SignalProducer<U, Error>

    Parameters

    transform

    The closure used to obtain the returned value from this producer’s underlying value.

    Return Value

    A producer that, when started, sends values obtained using transform as this producer sends values.

  • Preserve only values which pass the given closure.

    Declaration

    Swift

    public func filter(_ isIncluded: @escaping (Value) -> Bool) -> SignalProducer<Value, Error>

    Parameters

    isIncluded

    A closure to determine whether a value from self should be included in the produced Signal.

    Return Value

    A producer that, when started, forwards the values passing the given closure.

  • Applies transform to values from the producer and forwards values with non nil results unwrapped.

    Declaration

    Swift

    public func filterMap<U>(_ transform: @escaping (Value) -> U?) -> SignalProducer<U, Error>

    Parameters

    transform

    A closure that accepts a value from the value event and returns a new optional value.

    Return Value

    A producer that will send new values, that are non nil after the transformation.

  • Yield the first count values from the input producer.

    Precondition

    count must be non-negative number.

    Declaration

    Swift

    public func take(first count: Int) -> SignalProducer<Value, Error>

    Parameters

    count

    A number of values to take from the signal.

    Return Value

    A producer that, when started, will yield the first count values from self.

  • Yield an array of values when self completes.

    Note

    When self completes without collecting any value, it will send an empty array of values.

    Declaration

    Swift

    public func collect() -> SignalProducer<[Value], Error>

    Return Value

    A producer that, when started, will yield an array of values when self completes.

  • Yield an array of values until it reaches a certain count.

    Precondition

    count must be greater than zero.

    Note

    When the count is reached the array is sent and the signal starts over yielding a new array of values.

    Note

    When self completes any remaining values will be sent, the last array may not have count values. Alternatively, if were not collected any values will sent an empty array of values.

    Declaration

    Swift

    public func collect(count: Int) -> SignalProducer<[Value], Error>

    Return Value

    A producer that, when started, collects at most count values from self, forwards them as a single array and completes.

  • Collect values from self, and emit them if the predicate passes.

    When self completes any remaining values will be sent, regardless of the collected values matching shouldEmit or not.

    If self completes without having emitted any value, an empty array would be emitted, followed by the completion of the produced Signal.

    let (producer, observer) = SignalProducer<Int, NoError>.buffer(1)
    
    producer
        .collect { values in values.reduce(0, combine: +) == 8 }
        .startWithValues { print($0) }
    
    observer.send(value: 1)
    observer.send(value: 3)
    observer.send(value: 4)
    observer.send(value: 7)
    observer.send(value: 1)
    observer.send(value: 5)
    observer.send(value: 6)
    observer.sendCompleted()
    
    // Output:
    // [1, 3, 4]
    // [7, 1]
    // [5, 6]
    

    Declaration

    Swift

    public func collect(_ shouldEmit: @escaping (_ values: [Value]) -> Bool) -> SignalProducer<[Value], Error>

    Parameters

    shouldEmit

    A closure to determine, when every time a new value is received, whether the collected values should be emitted.

    Return Value

    A producer of arrays of values, as instructed by the shouldEmit closure.

  • Collect values from self, and emit them if the predicate passes.

    When self completes any remaining values will be sent, regardless of the collected values matching shouldEmit or not.

    If self completes without having emitted any value, an empty array would be emitted, followed by the completion of the produced Signal.

    let (producer, observer) = SignalProducer<Int, NoError>.buffer(1)
    
    producer
        .collect { values, value in value == 7 }
        .startWithValues { print($0) }
    
    observer.send(value: 1)
    observer.send(value: 1)
    observer.send(value: 7)
    observer.send(value: 7)
    observer.send(value: 5)
    observer.send(value: 6)
    observer.sendCompleted()
    
    // Output:
    // [1, 1]
    // [7]
    // [7, 5, 6]
    

    Declaration

    Swift

    public func collect(_ shouldEmit: @escaping (_ collected: [Value], _ latest: Value) -> Bool) -> SignalProducer<[Value], Error>

    Parameters

    shouldEmit

    A closure to determine, when every time a new value is received, whether the collected values should be emitted. The new value is not included in the collected values, and is included when the next value is received.

    Return Value

    A producer of arrays of values, as instructed by the shouldEmit closure.

  • Forward the latest values on scheduler every interval.

    Note

    If self terminates while values are being accumulated, the behaviour will be determined by discardWhenCompleted. If true, the values will be discarded and the returned producer will terminate immediately. If false, that values will be delivered at the next interval.

    Declaration

    Swift

    public func collect(every interval: DispatchTimeInterval, on scheduler: DateScheduler, skipEmpty: Bool = false, discardWhenCompleted: Bool = true) -> SignalProducer<[Value], Error>

    Parameters

    interval

    A repetition interval.

    scheduler

    A scheduler to send values on.

    skipEmpty

    Whether empty arrays should be sent if no values were accumulated during the interval.

    discardWhenCompleted

    A boolean to indicate if the latest unsent values should be discarded on completion.

    Return Value

    A producer that sends all values that are sent from self at interval seconds apart.

  • Forward all events onto the given scheduler, instead of whichever scheduler they originally arrived upon.

    Declaration

    Swift

    public func observe(on scheduler: Scheduler) -> SignalProducer<Value, Error>

    Parameters

    scheduler

    A scheduler to deliver events on.

    Return Value

    A producer that, when started, will yield self values on provided scheduler.

  • Combine the latest value of the receiver with the latest value from the given producer.

    Note

    The returned producer will not send a value until both inputs have sent at least one value each.

    Note

    If either producer is interrupted, the returned producer will also be interrupted.

    Note

    The returned producer will not complete until both inputs complete.

    Declaration

    Swift

    public func combineLatest<U>(with other: SignalProducer<U, Error>) -> SignalProducer<(Value, U), Error>

    Parameters

    other

    A producer to combine self‘s value with.

    Return Value

    A producer that, when started, will yield a tuple containing values of self and given producer.

  • Combine the latest value of the receiver with the latest value from the given producer.

    Note

    The returned producer will not send a value until both inputs have sent at least one value each.

    Note

    If either producer is interrupted, the returned producer will also be interrupted.

    Note

    The returned producer will not complete until both inputs complete.

    Declaration

    Swift

    public func combineLatest<Other>(with other: Other) -> SignalProducer<(Value, Other.Value), Error> where Error == Other.Error, Other : SignalProducerConvertible

    Parameters

    other

    A producer to combine self‘s value with.

    Return Value

    A producer that, when started, will yield a tuple containing values of self and given producer.

  • Merge the given producer into a single SignalProducer that will emit all values from both of them, and complete when all of them have completed.

    Declaration

    Swift

    public func merge(with other: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>

    Parameters

    other

    A producer to merge self‘s value with.

    Return Value

    A producer that sends all values of self and given producer.

  • Merge the given producer into a single SignalProducer that will emit all values from both of them, and complete when all of them have completed.

    Declaration

    Swift

    public func merge<Other>(with other: Other) -> SignalProducer<Value, Error> where Value == Other.Value, Error == Other.Error, Other : SignalProducerConvertible

    Parameters

    other

    A producer to merge self‘s value with.

    Return Value

    A producer that sends all values of self and given producer.

  • Delay value and completed events by the given interval, forwarding them on the given scheduler.

    Note

    failed and interrupted events are always scheduled immediately.

    Declaration

    Swift

    public func delay(_ interval: TimeInterval, on scheduler: DateScheduler) -> SignalProducer<Value, Error>

    Parameters

    interval

    Interval to delay value and completed events by.

    scheduler

    A scheduler to deliver delayed events on.

    Return Value

    A producer that, when started, will delay value and completed events and will yield them on given scheduler.

  • Skip the first count values, then forward everything afterward.

    Declaration

    Swift

    public func skip(first count: Int) -> SignalProducer<Value, Error>

    Parameters

    count

    A number of values to skip.

    Return Value

    A producer that, when started, will skip the first count values, then forward everything afterward.

  • Treats all Events from the input producer as plain values, allowing them to be manipulated just like any other value.

    In other words, this brings Events “into the monad.”

    Note

    When a Completed or Failed event is received, the resulting producer will send the Event itself and then complete. When an interrupted event is received, the resulting producer will send the Event itself and then interrupt.

    Declaration

    Swift

    public func materialize() -> SignalProducer<ProducedSignal.Event, NoError>

    Return Value

    A producer that sends events as its values.

  • Forward the latest value from self with the value from sampler as a tuple, only when sampler sends a value event.

    Note

    If sampler fires before a value has been observed on self, nothing happens.

    Declaration

    Swift

    public func sample<U>(with sampler: SignalProducer<U, NoError>) -> SignalProducer<(Value, U), Error>

    Parameters

    sampler

    A producer that will trigger the delivery of value event from self.

    Return Value

    A producer that will send values from self and sampler, sampled (possibly multiple times) by sampler, then complete once both input producers have completed, or interrupt if either input producer is interrupted.

  • Forward the latest value from self with the value from sampler as a tuple, only when sampler sends a value event.

    Note

    If sampler fires before a value has been observed on self, nothing happens.

    Declaration

    Swift

    public func sample<Sampler>(with sampler: Sampler) -> SignalProducer<(Value, Sampler.Value), Error> where Sampler : SignalProducerConvertible, Sampler.Error == NoError

    Parameters

    sampler

    A producer that will trigger the delivery of value event from self.

    Return Value

    A producer that will send values from self and sampler, sampled (possibly multiple times) by sampler, then complete once both input producers have completed, or interrupt if either input producer is interrupted.

  • Forward the latest value from self whenever sampler sends a value event.

    Note

    If sampler fires before a value has been observed on self, nothing happens.

    Declaration

    Swift

    public func sample(on sampler: SignalProducer<(), NoError>) -> SignalProducer<Value, Error>

    Parameters

    sampler

    A producer that will trigger the delivery of value event from self.

    Return Value

    A producer that, when started, will send values from self, sampled (possibly multiple times) by sampler, then complete once both input producers have completed, or interrupt if either input producer is interrupted.

  • Forward the latest value from self whenever sampler sends a value event.

    Note

    If sampler fires before a value has been observed on self, nothing happens.

    Declaration

    Swift

    public func sample<Sampler>(on sampler: Sampler) -> SignalProducer<Value, Error> where Sampler : SignalProducerConvertible, Sampler.Error == NoError, Sampler.Value == ()

    Parameters

    sampler

    A producer that will trigger the delivery of value event from self.

    Return Value

    A producer that, when started, will send values from self, sampled (possibly multiple times) by sampler, then complete once both input producers have completed, or interrupt if either input producer is interrupted.

  • Forward the latest value from samplee with the value from self as a tuple, only when self sends a value event. This is like a flipped version of sample(with:), but samplee‘s terminal events are completely ignored.

    Note

    If self fires before a value has been observed on samplee, nothing happens.

    Declaration

    Swift

    public func withLatest<U>(from samplee: SignalProducer<U, NoError>) -> SignalProducer<(Value, U), Error>

    Parameters

    samplee

    A producer whose latest value is sampled by self.

    Return Value

    A producer that will send values from self and samplee, sampled (possibly multiple times) by self, then terminate once self has terminated. samplee‘s terminated events are ignored.

  • Forward the latest value from samplee with the value from self as a tuple, only when self sends a value event. This is like a flipped version of sample(with:), but samplee‘s terminal events are completely ignored.

    Note

    If self fires before a value has been observed on samplee, nothing happens.

    Declaration

    Swift

    public func withLatest<Samplee>(from samplee: Samplee) -> SignalProducer<(Value, Samplee.Value), Error> where Samplee : SignalProducerConvertible, Samplee.Error == NoError

    Parameters

    samplee

    A producer whose latest value is sampled by self.

    Return Value

    A producer that will send values from self and samplee, sampled (possibly multiple times) by self, then terminate once self has terminated. samplee‘s terminated events are ignored.

  • Forwards events from self until lifetime ends, at which point the returned producer will complete.

    Declaration

    Swift

    public func take(during lifetime: Lifetime) -> SignalProducer<Value, Error>

    Parameters

    lifetime

    A lifetime whose ended signal will cause the returned producer to complete.

    Return Value

    A producer that will deliver events until lifetime ends.

  • Forward events from self until trigger sends a value or completed event, at which point the returned producer will complete.

    Declaration

    Swift

    public func take(until trigger: SignalProducer<(), NoError>) -> SignalProducer<Value, Error>

    Parameters

    trigger

    A producer whose value or completed events will stop the delivery of value events from self.

    Return Value

    A producer that will deliver events until trigger sends value or completed events.

  • Forward events from self until trigger sends a value or completed event, at which point the returned producer will complete.

    Declaration

    Swift

    public func take<Trigger>(until trigger: Trigger) -> SignalProducer<Value, Error> where Trigger : SignalProducerConvertible, Trigger.Error == NoError, Trigger.Value == ()

    Parameters

    trigger

    A producer whose value or completed events will stop the delivery of value events from self.

    Return Value

    A producer that will deliver events until trigger sends value or completed events.

  • Do not forward any values from self until trigger sends a value or completed, at which point the returned producer behaves exactly like producer.

    Declaration

    Swift

    public func skip(until trigger: SignalProducer<(), NoError>) -> SignalProducer<Value, Error>

    Parameters

    trigger

    A producer whose value or completed events will start the deliver of events on self.

    Return Value

    A producer that will deliver events once the trigger sends value or completed events.

  • Do not forward any values from self until trigger sends a value or completed, at which point the returned producer behaves exactly like producer.

    Declaration

    Swift

    public func skip<Trigger>(until trigger: Trigger) -> SignalProducer<Value, Error> where Trigger : SignalProducerConvertible, Trigger.Error == NoError, Trigger.Value == ()

    Parameters

    trigger

    A producer whose value or completed events will start the deliver of events on self.

    Return Value

    A producer that will deliver events once the trigger sends value or completed events.

  • Forward events from self with history: values of the returned producer are a tuples whose first member is the previous value and whose second member is the current value. initial is supplied as the first member when self sends its first value.

    Declaration

    Swift

    public func combinePrevious(_ initial: Value) -> SignalProducer<(Value, Value), Error>

    Parameters

    initial

    A value that will be combined with the first value sent by self.

    Return Value

    A producer that sends tuples that contain previous and current sent values of self.

  • Forward events from self with history: values of the produced signal are a tuples whose first member is the previous value and whose second member is the current value.

    The produced Signal would not emit any tuple until it has received at least two values.

    Declaration

    Swift

    public func combinePrevious() -> SignalProducer<(Value, Value), Error>

    Return Value

    A producer that sends tuples that contain previous and current sent values of self.

  • Combine all values from self, and forward the final result.

    See scan(_:_:) if the resulting producer needs to forward also the partial results.

    Declaration

    Swift

    public func reduce<U>(_ initialResult: U, _ nextPartialResult: @escaping (U, Value) -> U) -> SignalProducer<U, Error>

    Parameters

    initialResult

    The value to use as the initial accumulating value.

    nextPartialResult

    A closure that combines the accumulating value and the latest value from self. The result would be used in the next call of nextPartialResult, or emit to the returned Signal when self completes.

    Return Value

    A producer that sends the final result as self completes.

  • Combine all values from self, and forward the final result.

    See scan(into:_:) if the resulting producer needs to forward also the partial results.

    Declaration

    Swift

    public func reduce<U>(into initialResult: U, _ nextPartialResult: @escaping (inout U, Value) -> Void) -> SignalProducer<U, Error>

    Parameters

    initialResult

    The value to use as the initial accumulating value.

    nextPartialResult

    A closure that combines the accumulating value and the latest value from self. The result would be used in the next call of nextPartialResult, or emit to the returned Signal when self completes.

    Return Value

    A producer that sends the final value as self completes.

  • Combine all values from self, and forward the partial results and the final result.

    See reduce(_:_:) if the resulting producer needs to forward only the final result.

    Declaration

    Swift

    public func scan<U>(_ initialResult: U, _ nextPartialResult: @escaping (U, Value) -> U) -> SignalProducer<U, Error>

    Parameters

    initialResult

    The value to use as the initial accumulating value.

    nextPartialResult

    A closure that combines the accumulating value and the latest value from self. The result would be forwarded, and would be used in the next call of nextPartialResult.

    Return Value

    A producer that sends the partial results of the accumuation, and the final result as self completes.

  • Combine all values from self, and forward the partial results and the final result.

    See reduce(into:_:) if the resulting producer needs to forward only the final result.

    Declaration

    Swift

    public func scan<U>(into initialResult: U, _ nextPartialResult: @escaping (inout U, Value) -> Void) -> SignalProducer<U, Error>

    Parameters

    initialResult

    The value to use as the initial accumulating value.

    nextPartialResult

    A closure that combines the accumulating value and the latest value from self. The result would be forwarded, and would be used in the next call of nextPartialResult.

    Return Value

    A producer that sends the partial results of the accumuation, and the final result as self completes.

  • Forward only values from self that are not considered equivalent to its immediately preceding value.

    Note

    The first value is always forwarded.

    Declaration

    Swift

    public func skipRepeats(_ isEquivalent: @escaping (Value, Value) -> Bool) -> SignalProducer<Value, Error>

    Parameters

    isEquivalent

    A closure to determine whether two values are equivalent.

    Return Value

    A producer which conditionally forwards values from self

  • Do not forward any value from self until shouldContinue returns false, at which point the returned signal starts to forward values from self, including the one leading to the toggling.

    Declaration

    Swift

    public func skip(while shouldContinue: @escaping (Value) -> Bool) -> SignalProducer<Value, Error>

    Parameters

    shouldContinue

    A closure to determine whether the skipping should continue.

    Return Value

    A producer which conditionally forwards values from self.

  • Forwards events from self until replacement begins sending events.

    Declaration

    Swift

    public func take(untilReplacement replacement: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>

    Parameters

    replacement

    A producer to wait to wait for values from and start sending them as a replacement to self‘s values.

    Return Value

    A producer which passes through value, failed, and interrupted events from self until replacement sends an event, at which point the returned producer will send that event and switch to passing through events from replacement instead, regardless of whether self has sent events already.

  • Forwards events from self until replacement begins sending events.

    Declaration

    Swift

    public func take<Replacement>(untilReplacement replacement: Replacement) -> SignalProducer<Value, Error> where Value == Replacement.Value, Error == Replacement.Error, Replacement : SignalProducerConvertible

    Parameters

    replacement

    A producer to wait to wait for values from and start sending them as a replacement to self‘s values.

    Return Value

    A producer which passes through value, failed, and interrupted events from self until replacement sends an event, at which point the returned producer will send that event and switch to passing through events from replacement instead, regardless of whether self has sent events already.

  • Wait until self completes and then forward the final count values on the returned producer.

    Declaration

    Swift

    public func take(last count: Int) -> SignalProducer<Value, Error>

    Parameters

    count

    Number of last events to send after self completes.

    Return Value

    A producer that receives up to count values from self after self completes.

  • Forward any values from self until shouldContinue returns false, at which point the produced Signal would complete.

    Declaration

    Swift

    public func take(while shouldContinue: @escaping (Value) -> Bool) -> SignalProducer<Value, Error>

    Parameters

    shouldContinue

    A closure to determine whether the forwarding of values should continue.

    Return Value

    A producer which conditionally forwards values from self.

  • Zip elements of two producers into pairs. The elements of any Nth pair are the Nth elements of the two input producers.

    Declaration

    Swift

    public func zip<U>(with other: SignalProducer<U, Error>) -> SignalProducer<(Value, U), Error>

    Parameters

    other

    A producer to zip values with.

    Return Value

    A producer that sends tuples of self and otherProducer.

  • Zip elements of two producers into pairs. The elements of any Nth pair are the Nth elements of the two input producers.

    Declaration

    Swift

    public func zip<Other>(with other: Other) -> SignalProducer<(Value, Other.Value), Error> where Error == Other.Error, Other : SignalProducerConvertible

    Parameters

    other

    A producer to zip values with.

    Return Value

    A producer that sends tuples of self and otherProducer.

  • Apply an action to every value from self, and forward the value if the action succeeds. If the action fails with an error, the produced Signal would propagate the failure and terminate.

    Declaration

    Swift

    public func attempt(_ action: @escaping (Value) -> Result<(), Error>) -> SignalProducer<Value, Error>

    Parameters

    action

    An action which yields a Result.

    Return Value

    A producer which forwards the values from self until the given action fails.

  • Apply a transform to every value from self, and forward the transformed value if the action succeeds. If the action fails with an error, the produced Signal would propagate the failure and terminate.

    Declaration

    Swift

    public func attemptMap<U>(_ action: @escaping (Value) -> Result<U, Error>) -> SignalProducer<U, Error>

    Parameters

    action

    A transform which yields a Result of the transformed value or the error.

    Return Value

    A producer which forwards the transformed values.

  • Forward the latest value on scheduler after at least interval seconds have passed since the returned signal last sent a value.

    If self always sends values more frequently than interval seconds, then the returned signal will send a value every interval seconds.

    To measure from when self last sent a value, see debounce.

    Seealso

    debounce

    Note

    If multiple values are received before the interval has elapsed, the latest value is the one that will be passed on.

    Note

    If self terminates while a value is being throttled, that value will be discarded and the returned producer will terminate immediately.

    Note

    If the device time changed backwards before previous date while a value is being throttled, and if there is a new value sent, the new value will be passed anyway.

    Declaration

    Swift

    public func throttle(_ interval: TimeInterval, on scheduler: DateScheduler) -> SignalProducer<Value, Error>

    Parameters

    interval

    Number of seconds to wait between sent values.

    scheduler

    A scheduler to deliver events on.

    Return Value

    A producer that sends values at least interval seconds appart on a given scheduler.

  • Conditionally throttles values sent on the receiver whenever shouldThrottle is true, forwarding values on the given scheduler.

    Note

    While shouldThrottle remains false, values are forwarded on the given scheduler. If multiple values are received while shouldThrottle is true, the latest value is the one that will be passed on.

    Note

    If the input signal terminates while a value is being throttled, that value will be discarded and the returned signal will terminate immediately.

    Note

    If shouldThrottle completes before the receiver, and its last value is true, the returned signal will remain in the throttled state, emitting no further values until it terminates.

    Declaration

    Swift

    public func throttle<P: PropertyProtocol>(while shouldThrottle: P, on scheduler: Scheduler) -> SignalProducer<Value, Error>
    	where P.Value == Bool

    Parameters

    shouldThrottle

    A boolean property that controls whether values should be throttled.

    scheduler

    A scheduler to deliver events on.

    Return Value

    A producer that sends values only while shouldThrottle is false.

  • Forward the latest value on scheduler after at least interval seconds have passed since self last sent a value.

    If self always sends values more frequently than interval seconds, then the returned signal will never send any values.

    To measure from when the returned signal last sent a value, see throttle.

    Seealso

    throttle

    Note

    If multiple values are received before the interval has elapsed, the latest value is the one that will be passed on.

    Note

    If self terminates while a value is being debounced, the behaviour will be determined by discardWhenCompleted. If true, that value will be discarded and the returned producer will terminate immediately. If false, that value will be delivered at the next debounce interval.

    Declaration

    Swift

    public func debounce(_ interval: TimeInterval, on scheduler: DateScheduler, discardWhenCompleted: Bool = true) -> SignalProducer<Value, Error>

    Parameters

    interval

    A number of seconds to wait before sending a value.

    scheduler

    A scheduler to send values on.

    discardWhenCompleted

    A boolean to indicate if the latest value should be discarded on completion.

    Return Value

    A producer that sends values that are sent from self at least interval seconds apart.

  • Forward events from self until interval. Then if producer isn’t completed yet, fails with error on scheduler.

    Note

    If the interval is 0, the timeout will be scheduled immediately. The producer must complete synchronously (or on a faster scheduler) to avoid the timeout.

    Declaration

    Swift

    public func timeout(after interval: TimeInterval, raising error: Error, on scheduler: DateScheduler) -> SignalProducer<Value, Error>

    Parameters

    interval

    Number of seconds to wait for self to complete.

    error

    Error to send with failed event if self is not completed when interval passes.

    scheduler

    A scheduler to deliver error on.

    Return Value

    A producer that sends events for at most interval seconds, then, if not completed - sends error with failed event on scheduler.

  • Unwraps non-nil values and forwards them on the returned signal, nil values are dropped.

    Declaration

    Swift

    public func skipNil() -> SignalProducer<Value.Wrapped, Error>

    Return Value

    A producer that sends only non-nil values.

  • The inverse of materialize(), this will translate a producer of Event values into a producer of those events themselves.

    Declaration

    Swift

    public func dematerialize() -> SignalProducer<Value.Value, Value.Error>

    Return Value

    A producer that sends values carried by self events.

  • Promote a producer that does not generate failures into one that can.

    Note

    This does not actually cause failers to be generated for the given producer, but makes it easier to combine with other producers that may fail; for example, with operators like combineLatestWith, zipWith, flatten, etc.

    Declaration

    Swift

    public func promoteError<F>(_: F.Type = F.self) -> SignalProducer<Value, F>

    Return Value

    A producer that has an instantiatable ErrorType.

  • Promote a producer that does not generate failures into one that can.

    Note

    This does not actually cause failers to be generated for the given producer, but makes it easier to combine with other producers that may fail; for example, with operators like combineLatestWith, zipWith, flatten, etc.

    Declaration

    Swift

    public func promoteError(_: Error.Type = Error.self) -> SignalProducer<Value, Error>

    Return Value

    A producer that has an instantiatable ErrorType.

  • Forward events from self until interval. Then if producer isn’t completed yet, fails with error on scheduler.

    Note

    If the interval is 0, the timeout will be scheduled immediately. The producer must complete synchronously (or on a faster scheduler) to avoid the timeout.

    Declaration

    Swift

    public func timeout<NewError>(
    	after interval: TimeInterval,
    	raising error: NewError,
    	on scheduler: DateScheduler
    ) -> SignalProducer<Value, NewError>

    Parameters

    interval

    Number of seconds to wait for self to complete.

    error

    Error to send with failed event if self is not completed when interval passes.

    scheudler

    A scheduler to deliver error on.

    Return Value

    A producer that sends events for at most interval seconds, then, if not completed - sends error with failed event on scheduler.

  • Apply a throwable action to every value from self, and forward the values if the action succeeds. If the action throws an error, the produced Signal would propagate the failure and terminate.

    Declaration

    Swift

    public func attempt(_ action: @escaping (Value) throws -> Void) -> SignalProducer<Value, AnyError>

    Parameters

    action

    A throwable closure to perform an arbitrary action on the value.

    Return Value

    A producer which forwards the successful values of the given action.

  • Apply a throwable action to every value from self, and forward the results if the action succeeds. If the action throws an error, the produced Signal would propagate the failure and terminate.

    Declaration

    Swift

    public func attemptMap<U>(_ action: @escaping (Value) throws -> U) -> SignalProducer<U, AnyError>

    Parameters

    action

    A throwable closure to perform an arbitrary action on the value, and yield a result.

    Return Value

    A producer which forwards the successful results of the given action.

  • Apply a throwable action to every value from self, and forward the values if the action succeeds. If the action throws an error, the produced Signal would propagate the failure and terminate.

    Declaration

    Swift

    public func attempt(_ action: @escaping (Value) throws -> Void) -> SignalProducer<Value, AnyError>

    Parameters

    action

    A throwable closure to perform an arbitrary action on the value.

    Return Value

    A producer which forwards the successful values of the given action.

  • Apply a throwable transform to every value from self, and forward the results if the action succeeds. If the transform throws an error, the produced Signal would propagate the failure and terminate.

    Declaration

    Swift

    public func attemptMap<U>(_ transform: @escaping (Value) throws -> U) -> SignalProducer<U, AnyError>

    Parameters

    transform

    A throwable transform.

    Return Value

    A producer which forwards the successfully transformed values.

  • Promote a producer that does not generate values, as indicated by Never, to be a producer of the given type of value.

    Note

    The promotion does not result in any value being generated.

    Declaration

    Swift

    public func promoteValue<U>(_: U.Type = U.self) -> SignalProducer<U, Error>

    Return Value

    A producer that forwards all terminal events from self.

  • Promote a producer that does not generate values, as indicated by Never, to be a producer of the given type of value.

    Note

    The promotion does not result in any value being generated.

    Declaration

    Swift

    public func promoteValue(_: Value.Type = Value.self) -> SignalProducer<Value, Error>

    Return Value

    A producer that forwards all terminal events from self.

  • Forward only values from self that are not equal to its immediately preceding value.

    Note

    The first value is always forwarded.

    Declaration

    Swift

    public func skipRepeats() -> SignalProducer<Value, Error>

    Return Value

    A producer which conditionally forwards values from self.

  • Forward only those values from self that have unique identities across the set of all values that have been seen.

    Note

    This causes the identities to be retained to check for uniqueness.

    Declaration

    Swift

    public func uniqueValues<Identity: Hashable>(_ transform: @escaping (Value) -> Identity) -> SignalProducer<Value, Error>

    Parameters

    transform

    A closure that accepts a value and returns identity value.

    Return Value

    A producer that sends unique values during its lifetime.

  • Forward only those values from self that are unique across the set of all values that have been seen.

    Note

    This causes the values to be retained to check for uniqueness. Providing a function that returns a unique value for each sent value can help you reduce the memory footprint.

    Declaration

    Swift

    public func uniqueValues() -> SignalProducer<Value, Error>

    Return Value

    A producer that sends unique values during its lifetime.

  • Injects side effects to be performed upon the specified producer events.

    Note

    In a composed producer, starting is invoked in the reverse direction of the flow of events.

    Declaration

    Swift

    public func on(
    	starting: (() -> Void)? = nil,
    	started: (() -> Void)? = nil,
    	event: ((ProducedSignal.Event) -> Void)? = nil,
    	failed: ((Error) -> Void)? = nil,
    	completed: (() -> Void)? = nil,
    	interrupted: (() -> Void)? = nil,
    	terminated: (() -> Void)? = nil,
    	disposed: (() -> Void)? = nil,
    	value: ((Value) -> Void)? = nil
    ) -> SignalProducer<Value, Error>

    Parameters

    starting

    A closure that is invoked before the producer is started.

    started

    A closure that is invoked after the producer is started.

    event

    A closure that accepts an event and is invoked on every received event.

    failed

    A closure that accepts error object and is invoked for failed event.

    completed

    A closure that is invoked for completed event.

    interrupted

    A closure that is invoked for interrupted event.

    terminated

    A closure that is invoked for any terminating event.

    disposed

    A closure added as disposable when signal completes.

    value

    A closure that accepts a value from value event.

    Return Value

    A producer with attached side-effects for given event cases.

  • Start the returned producer on the given Scheduler.

    Note

    This implies that any side effects embedded in the producer will be performed on the given scheduler as well.

    Note

    Events may still be sent upon other schedulers — this merely affects where the start() method is run.

    Declaration

    Swift

    public func start(on scheduler: Scheduler) -> SignalProducer<Value, Error>

    Parameters

    scheduler

    A scheduler to deliver events on.

    Return Value

    A producer that will deliver events on given scheduler when started.

  • Repeat self a total of count times. In other words, start producer count number of times, each one after previously started producer completes.

    Note

    Repeating 1 time results in an equivalent signal producer.

    Note

    Repeating 0 times results in a producer that instantly completes.

    Precondition

    count must be non-negative integer.

    Declaration

    Swift

    public func `repeat`(_ count: Int) -> SignalProducer<Value, Error>

    Parameters

    count

    Number of repetitions.

    Return Value

    A signal producer start sequentially starts self after previously started producer completes.

  • Ignore failures up to count times.

    Precondition

    count must be non-negative integer.

    Declaration

    Swift

    public func retry(upTo count: Int) -> SignalProducer<Value, Error>

    Parameters

    count

    Number of retries.

    Return Value

    A signal producer that restarts up to count times.

  • Delays retrying on failure by interval up to count attempts.

    Precondition

    count must be non-negative integer.

    Declaration

    Swift

    public func retry(upTo count: Int, interval: TimeInterval, on scheduler: DateScheduler) -> SignalProducer<Value, Error>

    Parameters

    count

    Number of retries.

    interval

    An interval between invocations.

    scheduler

    A scheduler to deliver events on.

    Return Value

    A signal producer that restarts up to count times.

  • Wait for completion of self, then forward all events from replacement. Any failure or interruption sent from self is forwarded immediately, in which case replacement will not be started, and none of its events will be be forwarded.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<U>(_ replacement: SignalProducer<U, NoError>) -> SignalProducer<U, Error>

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement. Any failure or interruption sent from self is forwarded immediately, in which case replacement will not be started, and none of its events will be be forwarded.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<Replacement>(_ replacement: Replacement) -> SignalProducer<Replacement.Value, Error> where Replacement : SignalProducerConvertible, Replacement.Error == NoError

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement. Any failure or interruption sent from self is forwarded immediately, in which case replacement will not be started, and none of its events will be be forwarded.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<U>(_ replacement: SignalProducer<U, Error>) -> SignalProducer<U, Error>

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement. Any failure or interruption sent from self is forwarded immediately, in which case replacement will not be started, and none of its events will be be forwarded.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<Replacement>(_ replacement: Replacement) -> SignalProducer<Replacement.Value, Error> where Error == Replacement.Error, Replacement : SignalProducerConvertible

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement. Any failure or interruption sent from self is forwarded immediately, in which case replacement will not be started, and none of its events will be be forwarded.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then(_ replacement: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement. Any failure or interruption sent from self is forwarded immediately, in which case replacement will not be started, and none of its events will be be forwarded.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<Replacement>(_ replacement: Replacement) -> SignalProducer<Value, Error> where Value == Replacement.Value, Error == Replacement.Error, Replacement : SignalProducerConvertible

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<U, F>(_ replacement: SignalProducer<U, F>) -> SignalProducer<U, F> where F : Error

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<Replacement>(_ replacement: Replacement) -> SignalProducer<Replacement.Value, Replacement.Error> where Replacement : SignalProducerConvertible

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<U>(_ replacement: SignalProducer<U, NoError>) -> SignalProducer<U, NoError>

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<Replacement>(_ replacement: Replacement) -> SignalProducer<Replacement.Value, NoError> where Replacement : SignalProducerConvertible, Replacement.Error == NoError

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then(_ replacement: SignalProducer<Value, NoError>) -> SignalProducer<Value, NoError>

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Wait for completion of self, then forward all events from replacement.

    Note

    All values sent from self are ignored.

    Declaration

    Swift

    public func then<Replacement>(_ replacement: Replacement) -> SignalProducer<Value, NoError> where Value == Replacement.Value, Replacement : SignalProducerConvertible, Replacement.Error == NoError

    Parameters

    replacement

    A producer to start when self completes.

    Return Value

    A producer that sends events from self and then from replacement when self completes.

  • Start the producer, then block, waiting for the first value.

    When a single value or error is sent, the returned Result will represent those cases. However, when no values are sent, nil will be returned.

    Declaration

    Swift

    public func first() -> Result<Value, Error>?

    Return Value

    Result when single value or failed event is received. nil when no events are received.

  • Start the producer, then block, waiting for events: value and completed.

    When a single value or error is sent, the returned Result will represent those cases. However, when no values are sent, or when more than one value is sent, nil will be returned.

    Declaration

    Swift

    public func single() -> Result<Value, Error>?

    Return Value

    Result when single value or failed event is received. nil when 0 or more than 1 events are received.

  • Start the producer, then block, waiting for the last value.

    When a single value or error is sent, the returned Result will represent those cases. However, when no values are sent, nil will be returned.

    Declaration

    Swift

    public func last() -> Result<Value, Error>?

    Return Value

    Result when single value or failed event is received. nil when no events are received.

  • Starts the producer, then blocks, waiting for completion.

    When a completion or error is sent, the returned Result will represent those cases.

    Declaration

    Swift

    public func wait() -> Result<(), Error>

    Return Value

    Result when single completion or failed event is received.

  • Creates a new SignalProducer that will multicast values emitted by the underlying producer, up to capacity. This means that all clients of this SignalProducer will see the same version of the emitted values/errors.

    The underlying SignalProducer will not be started until self is started for the first time. When subscribing to this producer, all previous values (up to capacity) will be emitted, followed by any new values.

    If you find yourself needing the current value (the last buffered value) you should consider using PropertyType instead, which, unlike this operator, will guarantee at compile time that there’s always a buffered value. This operator is not recommended in most cases, as it will introduce an implicit relationship between the original client and the rest, so consider alternatives like PropertyType, or representing your stream using a Signal instead.

    This operator is only recommended when you absolutely need to introduce a layer of caching in front of another SignalProducer.

    Precondition

    capacity must be non-negative integer.

    Declaration

    Swift

    public func replayLazily(upTo capacity: Int) -> SignalProducer<Value, Error>

    Parameters

    capacity

    Number of values to hold.

    Return Value

    A caching producer that will hold up to last capacity values.

  • Create a producer that computes a logical NOT in the latest values of self.

    Declaration

    Swift

    public func negate() -> SignalProducer<Value, Error>

    Return Value

    A producer that emits the logical NOT results.

  • Create a producer that computes a logical AND between the latest values of self and producer.

    Declaration

    Swift

    public func and(_ booleans: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>

    Parameters

    booleans

    A producer of booleans to be combined with self.

    Return Value

    A producer that emits the logical AND results.

  • Create a producer that computes a logical AND between the latest values of self and producer.

    Declaration

    Swift

    public func and<Booleans>(_ booleans: Booleans) -> SignalProducer<Value, Error> where Error == Booleans.Error, Booleans : SignalProducerConvertible, Booleans.Value == Bool

    Parameters

    booleans

    A producer of booleans to be combined with self.

    Return Value

    A producer that emits the logical AND results.

  • Create a producer that computes a logical OR between the latest values of self and producer.

    Declaration

    Swift

    public func or(_ booleans: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>

    Parameters

    booleans

    A producer of booleans to be combined with self.

    Return Value

    A producer that emits the logical OR results.

  • Create a producer that computes a logical OR between the latest values of self and producer.

    Declaration

    Swift

    public func or<Booleans>(_ booleans: Booleans) -> SignalProducer<Value, Error> where Error == Booleans.Error, Booleans : SignalProducerConvertible, Booleans.Value == Bool

    Parameters

    booleans

    A producer of booleans to be combined with self.

    Return Value

    A producer that emits the logical OR results.

  • Create a repeating timer of the given interval, with a reasonable default leeway, sending updates on the given scheduler.

    Note

    This timer will never complete naturally, so all invocations of start() must be disposed to avoid leaks.

    Precondition

    interval must be non-negative number.

    Note

    If you plan to specify an interval value greater than 200,000 seconds, use timer(interval:on:leeway:) instead and specify your own leeway value to avoid potential overflow.

    Declaration

    Swift

    public static func timer(interval: DispatchTimeInterval, on scheduler: DateScheduler) -> SignalProducer<Value, Error>

    Parameters

    interval

    An interval between invocations.

    scheduler

    A scheduler to deliver events on.

    Return Value

    A producer that sends NSDate values every interval seconds.

  • Creates a repeating timer of the given interval, sending updates on the given scheduler.

    Note

    This timer will never complete naturally, so all invocations of start() must be disposed to avoid leaks.

    Precondition

    interval must be non-negative number.

    Precondition

    leeway must be non-negative number.

    Declaration

    Swift

    public static func timer(interval: DispatchTimeInterval, on scheduler: DateScheduler, leeway: DispatchTimeInterval) -> SignalProducer<Value, Error>

    Parameters

    interval

    An interval between invocations.

    scheduler

    A scheduler to deliver events on.

    leeway

    Interval leeway. Apple’s Power Efficiency Guide for Mac Apps recommends a leeway of at least 10% of the timer interval.

    Return Value

    A producer that sends NSDate values every interval seconds.