Signal

public final class Signal<Value, Error: Swift.Error>

A push-driven stream that sends Events over time, parameterized by the type of values being sent (Value) and the type of failure that can occur (Error). If no failures should be possible, NoError can be specified for Error.

An observer of a Signal will see the exact same sequence of events as all other observers. In other words, events will be sent to all observers at the same time.

Signals are generally used to represent event streams that are already “in progress,” like notifications, user input, etc. To represent streams that must first be started, see the SignalProducer type.

A Signal is kept alive until either of the following happens: 1. its input observer receives a terminating event; or 2. it has no active observers, and is not being retained.

  • Initialize a Signal that will immediately invoke the given generator, then forward events sent to the given observer.

    Note

    The disposable returned from the closure will be automatically disposed if a terminating event is sent to the observer. The Signal itself will remain alive until the observer is released.

    See more

    Declaration

    Swift

    public init(_ generator: (Observer) -> Disposable?)

    Parameters

    generator

    A closure that accepts an implicitly created observer that will act as an event emitter for the signal.

  • A Signal that never sends any events to its observers.

    Declaration

    Swift

    public static var never: Signal
  • A Signal that completes immediately without emitting any value.

    Declaration

    Swift

    public static var empty: Signal
  • Create a Signal that will be controlled by sending events to an input observer.

    Note

    The Signal will remain alive until a terminating event is sent to the input observer, or until it has no observers and there are no strong references to it.

    Declaration

    Swift

    public static func pipe(disposable: Disposable? = nil) -> (output: Signal, input: Observer)

    Parameters

    disposable

    An optional disposable to associate with the signal, and to be disposed of when the signal terminates.

    Return Value

    A tuple of output: Signal, the output end of the pipe, and input: Observer, the input end of the pipe.

  • Observe the Signal by sending any future events to the given observer.

    Note

    If the Signal has already terminated, the observer will immediately receive an interrupted event.

    Declaration

    Swift

    public func observe(_ observer: Observer) -> Disposable?

    Parameters

    observer

    An observer to forward the events to.

    Return Value

    A Disposable which can be used to disconnect the observer, or nil if the signal has already terminated.

  • Extracts a signal from the receiver.

    Declaration

    Swift

    public var signal: Signal
  • Convenience override for observe(_:) to allow trailing-closure style invocations.

    Declaration

    Swift

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

    Parameters

    action

    A closure that will accept an event of the signal

    Return Value

    An optional Disposable which can be used to stop the invocation of the callback. Disposing of the Disposable will have no effect on the Signal itself.

  • Observe the Signal by invoking the given callback when value or failed event are received.

    Declaration

    Swift

    public func observeResult(_ result: @escaping (Result<Value, Error>) -> Void) -> Disposable?

    Parameters

    result

    A closure that accepts instance of Result<Value, Error> enum that contains either a .success(Value) or .failure<Error> case.

    Return Value

    An optional Disposable which can be used to stop the invocation of the callback. Disposing of the Disposable will have no effect on the Signal itself.

  • Observe the Signal by invoking the given callback when a completed event is received.

    Declaration

    Swift

    public func observeCompleted(_ completed: @escaping () -> Void) -> Disposable?

    Parameters

    completed

    A closure that is called when completed event is received.

    Return Value

    An optional Disposable which can be used to stop the invocation of the callback. Disposing of the Disposable will have no effect on the Signal itself.

  • Observe the Signal by invoking the given callback when a failed event is received.

    Returns a Disposable which can be used to stop the invocation of the callback. Disposing of the Disposable will have no effect on the Signal itself.

    Declaration

    Swift

    public func observeFailed(_ error: @escaping (Error) -> Void) -> Disposable?

    Parameters

    error

    A closure that is called when failed event is received. It accepts an error parameter.

  • Observe the Signal by invoking the given callback when an interrupted event is received. If the Signal has already terminated, the callback will be invoked immediately.

    Declaration

    Swift

    public func observeInterrupted(_ interrupted: @escaping () -> Void) -> Disposable?

    Parameters

    interrupted

    A closure that is invoked when interrupted event is received

    Return Value

    An optional Disposable which can be used to stop the invocation of the callback. Disposing of the Disposable will have no effect on the Signal itself.

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

    Declaration

    Swift

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

    Parameters

    transform

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

    Return Value

    A signal that will send new values.

  • Map errors in the signal to a new error.

    Declaration

    Swift

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

    Parameters

    transform

    A closure that accepts current error object and returns a new type of error object.

    Return Value

    A signal that will send new type of errors.

  • Maps each value in the signal 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 signal. 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) -> Signal<U, Error>

    Parameters

    transform

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

    Return Value

    A signal that sends values obtained using transform as this signal sends values.

  • Preserve only the values of the signal that pass the given predicate.

    Declaration

    Swift

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

    Parameters

    predicate

    A closure that accepts value and returns Bool denoting whether value has passed the test.

    Return Value

    A signal that will send only the values passing the given predicate.

  • Applies transform to values from signal and forwards values with non nil results unwrapped. - parameters: - transform: A closure that accepts a value from the value event and returns a new optional value.

    Declaration

    Swift

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

    Parameters

    transform

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

    Return Value

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

  • Take up to n values from the signal and then complete.

    Precondition

    count must be non-negative number.

    Declaration

    Swift

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

    Parameters

    count

    A number of values to take from the signal.

    Return Value

    A signal that will yield the first count values from self

  • Collect all values sent by the signal then forward them as a single array and complete.

    Note

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

    Declaration

    Swift

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

    Return Value

    A signal that will yield an array of values when self completes.

  • Collect at most count values from self, forward them as a single array and complete.

    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.

    Precondition

    count should be greater than zero.

    Declaration

    Swift

    public func collect(count: Int) -> Signal<[Value], Error>
  • Collect values that pass the given predicate then forward them as a single array and complete.

    Note

    When self completes any remaining values will be sent, the last array may not match predicate. Alternatively, if were not collected any values will sent an empty array of values.
    let (signal, observer) = Signal<Int, NoError>.pipe()
    
    signal
        .collect { values in values.reduce(0, combine: +) == 8 }
        .observeValues { 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(_ predicate: @escaping (_ values: [Value]) -> Bool) -> Signal<[Value], Error>

    Parameters

    predicate

    Predicate to match when values should be sent (returning true) or alternatively when they should be collected (where it should return false). The most recent value (value) is included in values and will be the end of the current array of values if the predicate returns true.

    Return Value

    A signal that collects values passing the predicate and, when self completes, forwards them as a single array and complets.

  • Repeatedly collect an array of values up to a matching value value. Then forward them as single array and wait for value events.

    Note

    When self completes any remaining values will be sent, the last array may not match predicate. Alternatively, if no values were collected an empty array will be sent.
    let (signal, observer) = Signal<Int, NoError>.pipe()
    
    signal
        .collect { values, value in value == 7 }
        .observeValues { 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(_ predicate: @escaping (_ values: [Value], _ value: Value) -> Bool) -> Signal<[Value], Error>

    Parameters

    predicate

    Predicate to match when values should be sent (returning true) or alternatively when they should be collected (where it should return false). The most recent value (value) is not included in values and will be the start of the next array of values if the predicate returns true.

    Return Value

    A signal that will yield an array of values based on a predicate which matches the values collected and the next value.

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

    Declaration

    Swift

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

    Parameters

    scheduler

    A scheduler to deliver events on.

    Return Value

    A signal that will yield self values on provided scheduler.

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

    Note

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

    Note

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

    Note

    The returned signal will not complete until both inputs complete.

    Declaration

    Swift

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

    Parameters

    otherSignal

    A signal to combine self’s value with.

    Return Value

    A signal that will yield a tuple containing values of self and given signal.

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

    Note

    failed and interrupted events are always scheduled immediately.

    Precondition

    interval must be non-negative number.

    Declaration

    Swift

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

    Parameters

    interval

    Interval to delay value and completed events by.

    scheduler

    A scheduler to deliver delayed events on.

    Return Value

    A signal that will delay value and completed events and will yield them on given scheduler.

  • Skip first count number of values then act as usual.

    Precondition

    count must be non-negative number.

    Declaration

    Swift

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

    Parameters

    count

    A number of values to skip.

    Return Value

    A signal that will skip the first count values, then forward everything afterward.

  • Treat all Events from self 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 signal will send the Event itself and then complete. When an Interrupted event is received, the resulting signal will send the Event itself and then interrupt.

    Declaration

    Swift

    public func materialize() -> Signal<Event<Value, Error>, NoError>

    Return Value

    A signal that sends events as its values.

  • Inject side effects to be performed upon the specified signal events.

    Declaration

    Swift

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

    Parameters

    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 signal with attached side-effects for given event cases.

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

    Note

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

    Declaration

    Swift

    public func sample<T>(with sampler: Signal<T, NoError>) -> Signal<(Value, T), Error>

    Parameters

    sampler

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

    Return Value

    A signal that will send values from self and sampler, sampled (possibly multiple times) by sampler, then complete once both input signals have completed, or interrupt if either input signal 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: Signal<(), NoError>) -> Signal<Value, Error>

    Parameters

    sampler

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

    Return Value

    A signal that will send values from self, sampled (possibly multiple times) by sampler, then complete once both input signals have completed, or interrupt if either input signal 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: Signal<U, NoError>) -> Signal<(Value, U), Error>

    Parameters

    samplee

    A signal whose latest value is sampled by self.

    Return Value

    A signal that will send values from self and samplee, sampled (possibly multiple times) by self, then terminate once self has terminated. .

  • 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>) -> Signal<(Value, U), Error>

    Parameters

    samplee

    A producer whose latest value is sampled by self.

    Return Value

    A signal that will send values from self and samplee, sampled (possibly multiple times) by self, then terminate once self has terminated. .

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

    Declaration

    Swift

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

    Parameters

    lifetime

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

    Return Value

    A signal that will deliver events until lifetime ends.

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

    Declaration

    Swift

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

    Parameters

    trigger

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

    Return Value

    A signal 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 event, at which point the returned signal behaves exactly like signal.

    Declaration

    Swift

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

    Parameters

    trigger

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

    Return Value

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

  • Forward events from self with history: values of the returned signal 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) -> Signal<(Value, Value), Error>

    Parameters

    initial

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

    Return Value

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

  • Send only the final value and then immediately completes.

    Declaration

    Swift

    public func reduce<U>(_ initial: U, _ combine: @escaping (U, Value) -> U) -> Signal<U, Error>

    Parameters

    initial

    Initial value for the accumulator.

    combine

    A closure that accepts accumulator and sent value of self.

    Return Value

    A signal that sends accumulated value after self completes.

  • Aggregate values into a single combined value. When self emits its first value, combine is invoked with initial as the first argument and that emitted value as the second argument. The result is emitted from the signal returned from scan. That result is then passed to combine as the first argument when the next value is emitted, and so on.

    Declaration

    Swift

    public func scan<U>(_ initial: U, _ combine: @escaping (U, Value) -> U) -> Signal<U, Error>

    Parameters

    initial

    Initial value for the accumulator.

    combine

    A closure that accepts accumulator and sent value of self.

    Return Value

    A signal that sends accumulated value each time self emits own value.

  • Forward only those values from self which do not pass isRepeat with respect to the previous value.

    Note

    The first value is always forwarded.

    Declaration

    Swift

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

    Parameters

    isRepeate

    A closure that accepts previous and current values of self and returns Bool whether these values are repeating.

    Return Value

    A signal that forwards only those values that fail given isRepeat predicate.

  • Do not forward any values from self until predicate returns false, at which point the returned signal behaves exactly like signal.

    Declaration

    Swift

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

    Parameters

    predicate

    A closure that accepts a value and returns whether self should still not forward that value to a signal.

    Return Value

    A signal that sends only forwarded values from self.

  • Forward events from self until replacement begins sending events.

    Declaration

    Swift

    public func take(untilReplacement signal: Signal<Value, Error>) -> Signal<Value, Error>

    Parameters

    replacement

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

    Return Value

    A signal which passes through value, failed, and interrupted events from self until replacement sends an event, at which point the returned signal 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 signal.

    Declaration

    Swift

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

    Parameters

    count

    Number of last events to send after self completes.

    Return Value

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

  • Forward any values from self until predicate returns false, at which point the returned signal will complete.

    Declaration

    Swift

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

    Parameters

    predicate

    A closure that accepts value and returns Bool value whether self should forward it to signal and continue sending other events.

    Return Value

    A signal that sends events until the values sent by self pass the given predicate.

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

    Declaration

    Swift

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

    Parameters

    otherSignal

    A signal to zip values with.

    Return Value

    A signal that sends tuples of self and otherSignal.

  • 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 signal 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.

    Precondition

    interval must be non-negative number.

    Declaration

    Swift

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

    Parameters

    interval

    Number of seconds to wait between sent values.

    scheduler

    A scheduler to deliver events on.

    Return Value

    A signal 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) -> Signal<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 signal 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 the input signal terminates while a value is being debounced, that value will be discarded and the returned signal will terminate immediately.

    Precondition

    interval must be non-negative number.

    Declaration

    Swift

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

    Parameters

    interval

    A number of seconds to wait before sending a value.

    scheduler

    A scheduler to send values on.

    Return Value

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

  • 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) -> Signal<Value, Error>

    Parameters

    transform

    A closure that accepts a value and returns identity value.

    Return Value

    A signal that sends unique values during its lifetime.

  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>) -> Signal<(Value, B), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>) -> Signal<(Value, B, C), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C, D>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>) -> Signal<(Value, B, C, D), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C, D, E>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>) -> Signal<(Value, B, C, D, E), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C, D, E, F>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>) -> Signal<(Value, B, C, D, E, F), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C, D, E, F, G>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>) -> Signal<(Value, B, C, D, E, F, G), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C, D, E, F, G, H>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>, _ h: Signal<H, Error>) -> Signal<(Value, B, C, D, E, F, G, H), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C, D, E, F, G, H, I>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>, _ h: Signal<H, Error>, _ i: Signal<I, Error>) -> Signal<(Value, B, C, D, E, F, G, H, I), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:).

    Declaration

    Swift

    public static func combineLatest<B, C, D, E, F, G, H, I, J>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>, _ h: Signal<H, Error>, _ i: Signal<I, Error>, _ j: Signal<J, Error>) -> Signal<(Value, B, C, D, E, F, G, H, I, J), Error>
  • Combines the values of all the given signals, in the manner described by combineLatest(with:). No events will be sent if the sequence is empty.

    Declaration

    Swift

    public static func combineLatest<S: Sequence>(_ signals: S) -> Signal<[Value], Error>
    		where S.Iterator.Element == Signal<Value, Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>) -> Signal<(Value, B), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>) -> Signal<(Value, B, C), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C, D>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>) -> Signal<(Value, B, C, D), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C, D, E>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>) -> Signal<(Value, B, C, D, E), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C, D, E, F>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>) -> Signal<(Value, B, C, D, E, F), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C, D, E, F, G>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>) -> Signal<(Value, B, C, D, E, F, G), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C, D, E, F, G, H>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>, _ h: Signal<H, Error>) -> Signal<(Value, B, C, D, E, F, G, H), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C, D, E, F, G, H, I>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>, _ h: Signal<H, Error>, _ i: Signal<I, Error>) -> Signal<(Value, B, C, D, E, F, G, H, I), Error>
  • Zips the values of all the given signals, in the manner described by zipWith.

    Declaration

    Swift

    public static func zip<B, C, D, E, F, G, H, I, J>(_ a: Signal<Value, Error>, _ b: Signal<B, Error>, _ c: Signal<C, Error>, _ d: Signal<D, Error>, _ e: Signal<E, Error>, _ f: Signal<F, Error>, _ g: Signal<G, Error>, _ h: Signal<H, Error>, _ i: Signal<I, Error>, _ j: Signal<J, Error>) -> Signal<(Value, B, C, D, E, F, G, H, I, J), Error>
  • Zips the values of all the given signals, in the manner described by zipWith. No events will be sent if the sequence is empty.

    Declaration

    Swift

    public static func zip<S: Sequence>(_ signals: S) -> Signal<[Value], Error>
    		where S.Iterator.Element == Signal<Value, Error>
  • Forward events from self until interval. Then if signal isn’t completed yet, fails with error on scheduler.

    Note

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

    Precondition

    interval must be non-negative number.

    Declaration

    Swift

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

    Parameters

    error

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

    interval

    Number of seconds to wait for self to complete.

    scheudler

    A scheduler to deliver error on.

    Return Value

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

  • Apply operation to values from self with successful results forwarded on the returned signal and failures sent as failed events.

    Declaration

    Swift

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

    Parameters

    operation

    A closure that accepts a value and returns a Result.

    Return Value

    A signal that receives successful Result as value event and failure as failed event.

  • Apply operation to values from self with successful results mapped on the returned signal and failures sent as failed events.

    Declaration

    Swift

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

    Parameters

    operation

    A closure that accepts a value and returns a result of a mapped value as success.

    Return Value

    A signal that sends mapped values from self if returned Result is successful, failed events otherwise.

  • Merges the given signals into a single Signal that will emit all values from each of them, and complete when all of them have completed.

    Declaration

    Swift

    public static func merge<Seq: Sequence, S: SignalProtocol>(_ signals: Seq) -> Signal<Value, Error>
    		where S.Value == Value, S.Error == Error, Seq.Iterator.Element == S

    Parameters

    signals

    A sequence of signals to merge.

  • Merges the given signals into a single Signal that will emit all values from each of them, and complete when all of them have completed.

    Declaration

    Swift

    public static func merge<S: SignalProtocol>(_ signals: S...) -> Signal<Value, Error>
    		where S.Value == Value, S.Error == Error

    Parameters

    signals

    A list of signals to merge.

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

    Warning

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

    Declaration

    Swift

    public func flatMap<U>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> SignalProducer<U, Error>) -> Signal<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 signal to a new signal, then flattens the resulting producers (into a signal of values), according to the semantics of the given strategy.

    Warning

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

    Declaration

    Swift

    public func flatMap<U>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> SignalProducer<U, NoError>) -> Signal<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 signal to a new signal, then flattens the resulting signals (into a signal of values), according to the semantics of the given strategy.

    Warning

    If signal or any of the created signals emit an error, the returned signal will forward that error immediately.

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

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

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

    Warning

    If signal emits an error, the returned signal will forward that error immediately.

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

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

  • Maps each event from signal to a new property, then flattens the resulting properties (into a signal of values), according to the semantics of the given strategy.

    Warning

    If signal emits an error, the returned signal will forward that error immediately.

    Declaration

    Swift

    public func flatMap<P: PropertyProtocol>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> P) -> Signal<P.Value, Error>

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

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

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

    Declaration

    Swift

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

    Parameters

    handler

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

  • 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.Signal> = LoggingEvent.Signal.allEvents, fileName: String = #file, functionName: String = #function, lineNumber: Int = #line, logger: @escaping EventLogger = defaultEventLog) -> Signal<Value, Error>

    Parameters

    identifier

    a string to identify the Signal 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 that, when observed, logs the fired events.

  • Observe the binding source by sending any events to the given observer.

    Declaration

    Swift

    public func observe(_ observer: Observer, during lifetime: Lifetime) -> Disposable?
  • Observe the Signal by invoking the given callback when value events are received.

    Declaration

    Swift

    public func observeValues(_ value: @escaping (Value) -> Void) -> Disposable?

    Parameters

    value

    A closure that accepts a value when value event is received.

    Return Value

    An optional Disposable which can be used to stop the invocation of the callback. Disposing of the Disposable will have no effect on the Signal itself.

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

    Note

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

    Declaration

    Swift

    public func promoteErrors<F: Swift.Error>(_: F.Type) -> Signal<Value, F>

    Parameters

    _

    An ErrorType.

    Return Value

    A signal that has an instantiatable ErrorType.

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

    Note

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

    Declaration

    Swift

    public func timeout<NewError: Swift.Error>(
    		after interval: TimeInterval,
    		raising error: NewError,
    		on scheduler: DateScheduler
    	) -> Signal<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 signal that sends events for at most interval seconds, then, if not completed - sends error with failed event on scheduler.

  • Apply a failable operation to values from self with successful results forwarded on the returned signal and thrown errors sent as failed events.

    Declaration

    Swift

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

    Parameters

    operation

    A failable closure that accepts a value.

    Return Value

    A signal that forwards successes as value events and thrown errors as failed events.

  • Apply a failable operation to values from self with successful results mapped on the returned signal and thrown errors sent as failed events.

    Declaration

    Swift

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

    Parameters

    operation

    A failable closure that accepts a value and attempts to transform it.

    Return Value

    A signal that sends successfully mapped values from self, or thrown errors as failed events.

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

    Warning

    If any of the created signals emit an error, the returned signal will forward that error immediately.

    Declaration

    Swift

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

    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 signal to a new signal, then flattens the resulting signals (into a signal of values), according to the semantics of the given strategy.

    Declaration

    Swift

    public func flatMap<U>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> SignalProducer<U, NoError>) -> Signal<U, 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 signal to a new signal, then flattens the resulting signals (into a signal of values), according to the semantics of the given strategy.

    Warning

    If any of the created signals emit an error, the returned signal will forward that error immediately.

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

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

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

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

    transform

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

  • Unwrap non-nil values and forward them on the returned signal, nil values are dropped.

    Declaration

    Swift

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

    Return Value

    A signal that sends only non-nil values.

  • Translate a signal of Event values into a signal of those events themselves.

    Declaration

    Swift

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

    Return Value

    A signal that sends values carried by self events.

  • Forward only those values from self which are not duplicates of the immedately preceding value.

    Note

    The first value is always forwarded.

    Declaration

    Swift

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

    Return Value

    A signal that does not send two equal values sequentially.

  • 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() -> Signal<Value, Error>

    Return Value

    A signal that sends unique values during its lifetime.

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

    Declaration

    Swift

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

    Return Value

    A signal that emits the logical NOT results.

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

    Declaration

    Swift

    public func and(_ signal: Signal<Value, Error>) -> Signal<Value, Error>

    Parameters

    signal

    Signal to be combined with self.

    Return Value

    A signal that emits the logical AND results.

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

    Declaration

    Swift

    public func or(_ signal: Signal<Value, Error>) -> Signal<Value, Error>

    Parameters

    signal

    Signal to be combined with self.

    Return Value

    A signal that emits the logical OR results.

  • Apply a failable operation to values from self with successful results forwarded on the returned signal and thrown errors sent as failed events.

    Declaration

    Swift

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

    Parameters

    operation

    A failable closure that accepts a value.

    Return Value

    A signal that forwards successes as value events and thrown errors as failed events.

  • Apply a failable operation to values from self with successful results mapped on the returned signal and thrown errors sent as failed events.

    Declaration

    Swift

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

    Parameters

    operation

    A failable closure that accepts a value and attempts to transform it.

    Return Value

    A signal that sends successfully mapped values from self, or thrown errors as failed events.

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

    Note

    If signal or an active inner producer 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) -> Signal<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 or an active inner producer 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) -> Signal<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.

    Warning

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

    Declaration

    Swift

    public func flatten(_ strategy: FlattenStrategy) -> Signal<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) -> Signal<Value.Value, Error>

    Parameters

    strategy

    Strategy used when flattening signals.

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

    Note

    If signal or an active inner signal emits an error, the returned signal will forward that error immediately.

    Warning

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

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

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

    Note

    If an active inner signal emits an error, the returned signal will forward that error immediately.

    Warning

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

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

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

    Warning

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

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

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

    Note

    If signal emits an error, the returned signal will forward that error immediately.

    Warning

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

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.

  • Flattens the sequence value sent by signal.

    Declaration

    Swift

    public func flatten() -> Signal<Value.Iterator.Element, Error>
  • Flattens the inner properties 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.

    Declaration

    Swift

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

    Parameters

    strategy

    Strategy used when flattening signals.