SignalProducer
public struct SignalProducer<Value, Error: Swift.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!
-
Initializes a
SignalProducerthat 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
signalA signal to observe after starting the producer.
-
Initializes a SignalProducer that will invoke the given closure once for each invocation of
start().The events that the closure puts into the given observer will become the events sent by the started
Signalto its observers.Note
If the
Disposablereturned fromstart()is disposed or a terminating event is sent to the observer, the givenCompositeDisposablewill be disposed, at which point work should be interrupted and any temporary resources cleaned up.Declaration
Swift
public init(_ startHandler: @escaping (Signal<Value, Error>.Observer, CompositeDisposable) -> Void)Parameters
startHandlerA closure that accepts observer and a disposable.
-
Creates a producer for a
Signalthat will immediately send one value then complete.Declaration
Swift
public init(value: Value)Parameters
valueA value that should be sent by the
Signalin avalueevent. -
Creates a producer for a
Signalthat immediately sends one value, then completes.This initializer differs from
init(value:)in that its solevalueevent is constructed lazily by invoking the suppliedactionwhen theSignalProduceris started.Declaration
Swift
public init(_ action: @escaping () -> Value)Parameters
actionA action that yields a value to be sent by the
Signalas avalueevent. -
Creates a producer for a
Signalthat will immediately fail with the given error.Declaration
Swift
public init(error: Error)Parameters
errorAn error that should be sent by the
Signalin afailedevent. -
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
resultA
Resultinstance that will send eithervalueevent ifresultissuccessful orfailedevent ifresultis afailure. -
Creates a producer for a Signal that will immediately send the values from the given sequence, then complete.
Declaration
Swift
public init<S: Sequence>(_ values: S) where S.Iterator.Element == ValueParameters
valuesA sequence of values that a
Signalwill send as separatevalueevents 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
firstFirst value for the
Signalto send.secondSecond value for the
Signalto send.tailRest of the values to be sent by the
Signal. -
A producer for a Signal that will immediately complete without sending any values.
Declaration
Swift
public static var empty: SignalProducer -
A producer for a Signal that never sends any events to its observers.
Declaration
Swift
public static var never: SignalProducer -
Create a Signal from the producer, pass it into the given closure, then start sending events on the Signal when the closure has returned.
The closure will also receive a disposable which can be used to interrupt the work associated with the signal and immediately send an
interruptedevent.Declaration
Swift
public func startWithSignal(_ setup: (_ signal: Signal<Value, Error>, _ interrupter: Disposable) -> Void)Parameters
setUpA closure that accepts a
signalandinterrupter.
-
Extracts a signal producer from the receiver.
Declaration
Swift
public var producer: SignalProducer -
Create a Signal from the producer, then attach the given observer to the
Signalas an observer.Declaration
Swift
public func start(_ observer: Signal<Value, Error>.Observer = .init()) -> DisposableParameters
observerAn observer to attach to produced signal.
Return Value
A
Disposablewhich can be used to interrupt the work associated with the signal and immediately send aninterruptedevent. -
Convenience override for start(_:) to allow trailing-closure style invocations.
Declaration
Swift
public func start(_ observerAction: @escaping Signal<Value, Error>.Observer.Action) -> DisposableParameters
observerActionA closure that accepts
Eventsent by the produced signal.Return Value
A
Disposablewhich can be used to interrupt the work associated with the signal and immediately send aninterruptedevent. -
Create a Signal from the producer, then add an observer to the
Signal, which will invoke the given callback whenvalueorfailedevents are received.Declaration
Swift
public func startWithResult(_ result: @escaping (Result<Value, Error>) -> Void) -> DisposableParameters
resultA closure that accepts a
resultthat contains a.successcase forvalueevents or.failurecase forfailedevent.Return Value
A Disposable which can be used to interrupt the work associated with the Signal, and prevent any future callbacks from being invoked.
-
Create a Signal from the producer, then add exactly one observer to the Signal, which will invoke the given callback when a
completedevent is received.Declaration
Swift
public func startWithCompleted(_ completed: @escaping () -> Void) -> DisposableParameters
completedA closure that will be envoked when produced signal sends
completedevent.Return Value
A
Disposablewhich can be used to interrupt the work associated with the signal. -
Creates a Signal from the producer, then adds exactly one observer to the Signal, which will invoke the given callback when a
failedevent is received.Declaration
Swift
public func startWithFailed(_ failed: @escaping (Error) -> Void) -> DisposableParameters
failedA closure that accepts an error object.
Return Value
A
Disposablewhich can be used to interrupt the work associated with the signal. -
Creates a Signal from the producer, then adds exactly one observer to the Signal, which will invoke the given callback when an
interruptedevent is received.Declaration
Swift
public func startWithInterrupted(_ interrupted: @escaping () -> Void) -> DisposableParameters
interruptedA closure that is invoked when
interruptedevent is received.Return Value
A
Disposablewhich can be used to interrupt the work associated with the signal. -
Lift an unary Signal operator to operate upon SignalProducers instead.
In other words, this will create a new
SignalProducerwhich will apply the givenSignaloperator to every createdSignal, just as if the operator had been applied to eachSignalyielded fromstart().Declaration
Parameters
transformAn 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
SignalProducerwhich will apply the givenSignaloperator to everySignalcreated from the two producers, just as if the operator had been applied to eachSignalyielded fromstart().Note
starting the returned producer will start the receiver of the operator, which may not be adviseable for some operators.
Declaration
Parameters
transformA binary operator to lift.
Return Value
A binary operator that operates on two signal producers.
-
Lift a binary Signal operator to operate upon a Signal and a SignalProducer instead.
In other words, this will create a new
SignalProducerwhich will apply the givenSignaloperator to everySignalcreated from the two producers, just as if the operator had been applied to eachSignalyielded fromstart().Declaration
Parameters
transformA binary operator to lift.
Return Value
A binary operator that works on
Signaland returnsSignalProducer. -
Map each value in the producer to a new value.
Declaration
Swift
public func map<U>(_ transform: @escaping (Value) -> U) -> SignalProducer<U, Error>Parameters
transformA 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 errors in the producer to a new error.
Declaration
Swift
public func mapError<F>(_ transform: @escaping (Error) -> F) -> SignalProducer<Value, F>Parameters
transformA 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. Ifschedulerhas not yet scheduledtransformfor execution, then each new value will replace the last one as the parameter totransformonce it is finally executed.Declaration
Swift
public func lazyMap<U>(on scheduler: Scheduler, transform: @escaping (Value) -> U) -> SignalProducer<U, Error>Parameters
transformThe closure used to obtain the returned value from this producer’s underlying value.
Return Value
A producer that, when started, sends values obtained using
transformas this producer sends values. -
Preserve only the values of the producer that pass the given predicate.
Declaration
Swift
public func filter(_ predicate: @escaping (Value) -> Bool) -> SignalProducer<Value, Error>Parameters
predicateA closure that accepts value and returns
Booldenoting whether value has passed the test.Return Value
A producer that, when started, will send only the values passing the given predicate.
-
Applies
transformto values from the producer and forwards values with nonnilresults unwrapped. - parameters: - transform: A closure that accepts a value from thevalueevent and returns a new optional value.Declaration
Swift
public func filterMap<U>(_ transform: @escaping (Value) -> U?) -> SignalProducer<U, Error>Parameters
transformA closure that accepts a value from the
valueevent and returns a new optional value.Return Value
A producer that will send new values, that are non
nilafter the transformation. -
Yield the first
countvalues from the input producer.Precondition
countmust be non-negative number.Declaration
Swift
public func take(first count: Int) -> SignalProducer<Value, Error>Parameters
countA number of values to take from the signal.
Return Value
A producer that, when started, will yield the first
countvalues fromself. -
Yield an array of values when
selfcompletes.Note
When
selfcompletes 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
selfcompletes. -
Yield an array of values until it reaches a certain count.
Precondition
countmust 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
selfcompletes any remaining values will be sent, the last array may not havecountvalues. 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
countvalues fromself, forwards them as a single array and completes. -
Yield an array of values based on a predicate which matches the values collected.
Note
Whenselfcompletes any remaining values will be sent, the last array may not matchpredicate. Alternatively, if were not collected any values will sent an empty array of values.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(_ predicate: @escaping (_ values: [Value]) -> Bool) -> SignalProducer<[Value], Error>Parameters
predicatePredicate to match when values should be sent (returning
true) or alternatively when they should be collected (where it should returnfalse). The most recent value (value) is included invaluesand will be the end of the current array of values if the predicate returnstrue.Return Value
A producer that, when started, collects values passing the predicate and, when
selfcompletes, forwards them as a single array and complets. -
Yield an array of values based on a predicate which matches the values collected and the next value.
Note
Whenselfcompletes any remaining values will be sent, the last array may not matchpredicate. Alternatively, if no values were collected an empty array will be sent.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(_ predicate: @escaping (_ values: [Value], _ value: Value) -> Bool) -> SignalProducer<[Value], Error>Parameters
predicatePredicate to match when values should be sent (returning
true) or alternatively when they should be collected (where it should returnfalse). The most recent value (vaule) is not included invaluesand will be the start of the next array of values if the predicate returnstrue.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) -> SignalProducer<Value, Error>Parameters
schedulerA scheduler to deliver events on.
Return Value
A producer that, when started, will yield
selfvalues 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
otherA producer to combine
self’s value with.Return Value
A producer that, when started, will yield a tuple containing values of
selfand given producer. -
Combine the latest value of the receiver with the latest value from the given signal.
Note
The returned producer will not send a value until both inputs have sent at least one value each.
Note
If either input 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: Signal<U, Error>) -> SignalProducer<(Value, U), Error>Parameters
otherA signal to combine
self’s value with.Return Value
A producer that, when started, will yield a tuple containing values of
selfand given signal. -
Delay
valueandcompletedevents by the given interval, forwarding them on the given scheduler.Note
failedandinterruptedevents are always scheduled immediately.Declaration
Swift
public func delay(_ interval: TimeInterval, on scheduler: DateScheduler) -> SignalProducer<Value, Error>Parameters
intervalInterval to delay
valueandcompletedevents by.schedulerA scheduler to deliver delayed events on.
Return Value
A producer that, when started, will delay
valueandcompletedevents and will yield them on given scheduler. -
Skip the first
countvalues, then forward everything afterward.Declaration
Swift
public func skip(first count: Int) -> SignalProducer<Value, Error>Parameters
countA number of values to skip.
Return Value
A producer that, when started, will skip the first
countvalues, 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
interruptedevent is received, the resulting producer will send theEventitself and then interrupt.Declaration
Swift
public func materialize() -> SignalProducer<Event<Value, Error>, NoError>Return Value
A producer that sends events as its values.
-
Forward the latest value from
selfwith the value fromsampleras a tuple, only whensamplersends avalueevent.Note
If
samplerfires before a value has been observed onself, nothing happens.Declaration
Swift
public func sample<T>(with sampler: SignalProducer<T, NoError>) -> SignalProducer<(Value, T), Error>Parameters
samplerA producer that will trigger the delivery of
valueevent fromself.Return Value
A producer that will send values from
selfandsampler, sampled (possibly multiple times) bysampler, then complete once both input producers have completed, or interrupt if either input producer is interrupted. -
Forward the latest value from
selfwith the value fromsampleras a tuple, only whensamplersends avalueevent.Note
If
samplerfires before a value has been observed onself, nothing happens.Declaration
Swift
public func sample<T>(with sampler: Signal<T, NoError>) -> SignalProducer<(Value, T), Error>Parameters
samplerA signal that will trigger the delivery of
valueevent fromself.Return Value
A producer that, when started, will send values from
selfandsampler, sampled (possibly multiple times) bysampler, then complete once both input producers have completed, or interrupt if either input producer is interrupted. -
Forward the latest value from
selfwheneversamplersends avalueevent.Note
If
samplerfires before a value has been observed onself, nothing happens.Declaration
Swift
public func sample(on sampler: SignalProducer<(), NoError>) -> SignalProducer<Value, Error>Parameters
samplerA producer that will trigger the delivery of
valueevent fromself.Return Value
A producer that, when started, will send values from
self, sampled (possibly multiple times) bysampler, then complete once both input producers have completed, or interrupt if either input producer is interrupted. -
Forward the latest value from
selfwheneversamplersends avalueevent.Note
If
samplerfires before a value has been observed onself, nothing happens.Declaration
Swift
public func sample(on sampler: Signal<(), NoError>) -> SignalProducer<Value, Error>Parameters
triggerA signal whose
valueorcompletedevents will start the deliver of events onself.Return Value
A producer that will send values from
self, sampled (possibly multiple times) bysampler, then complete once both inputs have completed, or interrupt if either input is interrupted. -
Forward the latest value from
sampleewith the value fromselfas a tuple, only whenselfsends avalueevent. This is like a flipped version ofsample(with:), butsamplee‘s terminal events are completely ignored.Note
If
selffires before a value has been observed onsamplee, nothing happens.Declaration
Swift
public func withLatest<U>(from samplee: SignalProducer<U, NoError>) -> SignalProducer<(Value, U), Error>Parameters
sampleeA producer whose latest value is sampled by
self.Return Value
A signal that will send values from
selfandsamplee, sampled (possibly multiple times) byself, then terminate onceselfhas terminated. . -
Forward the latest value from
sampleewith the value fromselfas a tuple, only whenselfsends avalueevent. This is like a flipped version ofsample(with:), butsamplee‘s terminal events are completely ignored.Note
If
selffires before a value has been observed onsamplee, nothing happens.Declaration
Swift
public func withLatest<U>(from samplee: Signal<U, NoError>) -> SignalProducer<(Value, U), Error>Parameters
sampleeA signal whose latest value is sampled by
self.Return Value
A signal that will send values from
selfandsamplee, sampled (possibly multiple times) byself, then terminate onceselfhas terminated. . -
Forwards events from
selfuntillifetimeends, at which point the returned producer will complete.Declaration
Swift
public func take(during lifetime: Lifetime) -> SignalProducer<Value, Error>Parameters
lifetimeA lifetime whose
endedsignal will cause the returned producer to complete.Return Value
A producer that will deliver events until
lifetimeends. -
Forward events from
selfuntiltriggersends avalueorcompletedevent, at which point the returned producer will complete.Declaration
Swift
public func take(until trigger: SignalProducer<(), NoError>) -> SignalProducer<Value, Error>Parameters
triggerA producer whose
valueorcompletedevents will stop the delivery ofvalueevents fromself.Return Value
A producer that will deliver events until
triggersendsvalueorcompletedevents. -
Forward events from
selfuntiltriggersends avalueorcompletedevent, at which point the returned producer will complete.Declaration
Swift
public func take(until trigger: Signal<(), NoError>) -> SignalProducer<Value, Error>Parameters
triggerA signal whose
valueorcompletedevents will stop the delivery ofvalueevents fromself.Return Value
A producer that will deliver events until
triggersendsvalueorcompletedevents. -
Do not forward any values from
selfuntiltriggersends avalueorcompleted, at which point the returned producer behaves exactly likeproducer.Declaration
Swift
public func skip(until trigger: SignalProducer<(), NoError>) -> SignalProducer<Value, Error>Parameters
triggerA producer whose
valueorcompletedevents will start the deliver of events onself.Return Value
A producer that will deliver events once the
triggersendsvalueorcompletedevents. -
Do not forward any values from
selfuntiltriggersends avalueorcompleted, at which point the returned signal behaves exactly likesignal.Declaration
Swift
public func skip(until trigger: Signal<(), NoError>) -> SignalProducer<Value, Error>Parameters
triggerA signal whose
valueorcompletedevents will start the deliver of events onself.Return Value
A producer that will deliver events once the
triggersendsvalueorcompletedevents. -
Forward events from
selfwith history: values of the returned producer are a tuple whose first member is the previous value and whose second member is the current value.initialis supplied as the first member whenselfsends its first value.Declaration
Swift
public func combinePrevious(_ initial: Value) -> SignalProducer<(Value, Value), Error>Parameters
initialA 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. -
Send only the final value and then immediately completes.
Declaration
Swift
public func reduce<U>(_ initial: U, _ combine: @escaping (U, Value) -> U) -> SignalProducer<U, Error>Parameters
initialInitial value for the accumulator.
combineA closure that accepts accumulator and sent value of
self.Return Value
A producer that sends accumulated value after
selfcompletes. -
Aggregate
self‘s values into a single combined value. Whenselfemits its first value,combineis invoked withinitialas the first argument and that emitted value as the second argument. The result is emitted from the producer returned fromscan. That result is then passed tocombineas 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) -> SignalProducer<U, Error>Parameters
initialInitial value for the accumulator.
combineA closure that accepts accumulator and sent value of
self.Return Value
A producer that sends accumulated value each time
selfemits own value. -
Forward only those values from
selfwhich do not passisRepeatwith respect to the previous value.Note
The first value is always forwarded.
Declaration
Swift
public func skipRepeats(_ isRepeat: @escaping (Value, Value) -> Bool) -> SignalProducer<Value, Error>Return Value
A producer that does not send two equal values sequentially.
-
Do not forward any values from
selfuntilpredicatereturns false, at which point the returned producer behaves exactly likeself.Declaration
Swift
public func skip(while predicate: @escaping (Value) -> Bool) -> SignalProducer<Value, Error>Parameters
predicateA closure that accepts a value and returns whether
selfshould still not forward that value to aproducer.Return Value
A producer that sends only forwarded values from
self. -
Forward events from
selfuntilreplacementbegins sending events.Declaration
Swift
public func take(untilReplacement signal: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>Parameters
replacementA 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, andinterruptedevents fromselfuntilreplacementsends an event, at which point the returned producer will send that event and switch to passing through events fromreplacementinstead, regardless of whetherselfhas sent events already. -
Forwards events from
selfuntilreplacementbegins sending events.Declaration
Swift
public func take(untilReplacement signal: Signal<Value, Error>) -> SignalProducer<Value, Error>Parameters
replacementA signal 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, andinterruptedevents fromselfuntilreplacementsends an event, at which point the returned producer will send that event and switch to passing through events fromreplacementinstead, regardless of whetherselfhas sent events already. -
Wait until
selfcompletes and then forward the finalcountvalues on the returned producer.Declaration
Swift
public func take(last count: Int) -> SignalProducer<Value, Error>Parameters
countNumber of last events to send after
selfcompletes.Return Value
A producer that receives up to
countvalues fromselfafterselfcompletes. -
Forward any values from
selfuntilpredicatereturns false, at which point the returned producer will complete.Declaration
Swift
public func take(while predicate: @escaping (Value) -> Bool) -> SignalProducer<Value, Error>Parameters
predicateA closure that accepts value and returns
Boolvalue whetherselfshould forward it tosignaland continue sending other events.Return Value
A producer that sends events until the values sent by
selfpass the givenpredicate. -
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
otherA producer to zip values with.
Return Value
A producer that sends tuples of
selfandotherProducer. -
Zip elements of this producer and a signal into pairs. The elements of any Nth pair are the Nth elements of the two.
Declaration
Swift
public func zip<U>(with other: Signal<U, Error>) -> SignalProducer<(Value, U), Error>Parameters
otherA signal to zip values with.
Return Value
A producer that sends tuples of
selfandotherSignal. -
Apply
operationto values fromselfwithsuccessful results forwarded on the returned producer andfailures sent asfailedevents.Declaration
Swift
public func attempt(operation: @escaping (Value) -> Result<(), Error>) -> SignalProducer<Value, Error>Parameters
operationA closure that accepts a value and returns a
Result.Return Value
A producer that receives
successfulResultasvalueevent andfailureasfailedevent. -
Apply
operationto values fromselfwithsuccessful results mapped on the returned producer andfailures sent asfailedevents.Declaration
Swift
public func attemptMap<U>(_ operation: @escaping (Value) -> Result<U, Error>) -> SignalProducer<U, Error>Parameters
operationA closure that accepts a value and returns a result of a mapped value as
success.Return Value
A producer that sends mapped values from
selfif returnedResultissuccessful,failedevents otherwise. -
Forward the latest value on
schedulerafter at leastintervalseconds have passed since the returned signal last sent a value.If
selfalways sends values more frequently thanintervalseconds, then the returned signal will send a value everyintervalseconds.To measure from when
selflast sent a value, seedebounce.Seealso
debounceNote
If multiple values are received before the interval has elapsed, the latest value is the one that will be passed on.
Note
If
selfterminates 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
intervalNumber of seconds to wait between sent values.
schedulerA scheduler to deliver events on.
Return Value
A producer that sends values at least
intervalseconds appart on a given scheduler. -
Conditionally throttles values sent on the receiver whenever
shouldThrottleis true, forwarding values on the given scheduler.Note
While
shouldThrottleremains false, values are forwarded on the given scheduler. If multiple values are received whileshouldThrottleis 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
shouldThrottlecompletes before the receiver, and its last value istrue, 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 == BoolParameters
shouldThrottleA boolean property that controls whether values should be throttled.
schedulerA scheduler to deliver events on.
Return Value
A producer that sends values only while
shouldThrottleis false. -
Forward the latest value on
schedulerafter at leastintervalseconds have passed sinceselflast sent a value.If
selfalways sends values more frequently thanintervalseconds, then the returned signal will never send any values.To measure from when the returned signal last sent a value, see
throttle.Seealso
throttleNote
If multiple values are received before the interval has elapsed, the latest value is the one that will be passed on.
Note
If
selfterminates while a value is being debounced, that value will be discarded and the returned producer will terminate immediately.Declaration
Swift
public func debounce(_ interval: TimeInterval, on scheduler: DateScheduler) -> SignalProducer<Value, Error>Parameters
intervalA number of seconds to wait before sending a value.
schedulerA scheduler to send values on.
Return Value
A producer that sends values that are sent from
selfat leastintervalseconds apart. -
Forward events from
selfuntilinterval. Then if producer isn’t completed yet, fails witherroronscheduler.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
intervalNumber of seconds to wait for
selfto complete.errorError to send with
failedevent ifselfis not completed whenintervalpasses.schedulerA scheduler to deliver error on.
Return Value
A producer that sends events for at most
intervalseconds, then, if notcompleted- sendserrorwithfailedevent onscheduler. -
Create a
SignalProducerthat will attempt the given operation once for each invocation ofstart().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 static func attempt(_ operation: @escaping () -> Result<Value, Error>) -> SignalProducer<Value, Error>Parameters
operationA closure that returns instance of
Result.Return Value
A
SignalProducerthat will forwardsuccessfulresultasvalueevent and then complete orfailedevent ifresultis afailure. -
Forward only those values from
selfthat 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
transformA closure that accepts a value and returns identity value.
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,
startingis invoked in the reverse direction of the flow of events.Declaration
Swift
public func on( starting: (() -> Void)? = nil, started: (() -> Void)? = nil, 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 ) -> SignalProducer<Value, Error>Parameters
startingA closure that is invoked before the producer is started.
startedA closure that is invoked after the producer is started.
eventA closure that accepts an event and is invoked on every received event.
failedA closure that accepts error object and is invoked for
failedevent.completedA closure that is invoked for
completedevent.interruptedA closure that is invoked for
interruptedevent.terminatedA closure that is invoked for any terminating event.
disposedA closure added as disposable when signal completes.
valueA closure that accepts a value from
valueevent.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
schedulerA scheduler to deliver events on.
Return Value
A producer that will deliver events on given
schedulerwhen started. -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>) -> SignalProducer<(Value, B), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>) -> SignalProducer<(Value, B, C), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C, D>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>) -> SignalProducer<(Value, B, C, D), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C, D, E>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>) -> SignalProducer<(Value, B, C, D, E), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C, D, E, F>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>) -> SignalProducer<(Value, B, C, D, E, F), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C, D, E, F, G>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>) -> SignalProducer<(Value, B, C, D, E, F, G), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C, D, E, F, G, H>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>, _ h: SignalProducer<H, Error>) -> SignalProducer<(Value, B, C, D, E, F, G, H), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C, D, E, F, G, H, I>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>, _ h: SignalProducer<H, Error>, _ i: SignalProducer<I, Error>) -> SignalProducer<(Value, B, C, D, E, F, G, H, I), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:).Declaration
Swift
public static func combineLatest<B, C, D, E, F, G, H, I, J>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>, _ h: SignalProducer<H, Error>, _ i: SignalProducer<I, Error>, _ j: SignalProducer<J, Error>) -> SignalProducer<(Value, B, C, D, E, F, G, H, I, J), Error> -
Combines the values of all the given producers, in the manner described by
combineLatest(with:). Will return an emptySignalProducerif the sequence is empty.Declaration
Swift
public static func combineLatest<S: Sequence>(_ producers: S) -> SignalProducer<[Value], Error> where S.Iterator.Element == SignalProducer<Value, Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>) -> SignalProducer<(Value, B), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>) -> SignalProducer<(Value, B, C), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C, D>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>) -> SignalProducer<(Value, B, C, D), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C, D, E>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>) -> SignalProducer<(Value, B, C, D, E), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C, D, E, F>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>) -> SignalProducer<(Value, B, C, D, E, F), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C, D, E, F, G>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>) -> SignalProducer<(Value, B, C, D, E, F, G), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C, D, E, F, G, H>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>, _ h: SignalProducer<H, Error>) -> SignalProducer<(Value, B, C, D, E, F, G, H), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C, D, E, F, G, H, I>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>, _ h: SignalProducer<H, Error>, _ i: SignalProducer<I, Error>) -> SignalProducer<(Value, B, C, D, E, F, G, H, I), Error> -
Zips the values of all the given producers, in the manner described by
zipWith.Declaration
Swift
public static func zip<B, C, D, E, F, G, H, I, J>(_ a: SignalProducer<Value, Error>, _ b: SignalProducer<B, Error>, _ c: SignalProducer<C, Error>, _ d: SignalProducer<D, Error>, _ e: SignalProducer<E, Error>, _ f: SignalProducer<F, Error>, _ g: SignalProducer<G, Error>, _ h: SignalProducer<H, Error>, _ i: SignalProducer<I, Error>, _ j: SignalProducer<J, Error>) -> SignalProducer<(Value, B, C, D, E, F, G, H, I, J), Error> -
Zips the values of all the given producers, in the manner described by
zipWith. Will return an emptySignalProducerif the sequence is empty.Declaration
Swift
public static func zip<S: Sequence>(_ producers: S) -> SignalProducer<[Value], Error> where S.Iterator.Element == SignalProducer<Value, Error> -
Repeat
selfa total ofcounttimes. In other words, start producercountnumber of times, each one after previously started producer completes.Note
Repeating
1time results in an equivalent signal producer.Note
Repeating
0times results in a producer that instantly completes.Precondition
countmust be non-negative integer.Declaration
Swift
public func `repeat`(_ count: Int) -> SignalProducer<Value, Error>Parameters
countNumber of repetitions.
Return Value
A signal producer start sequentially starts
selfafter previously started producer completes. -
Ignore failures up to
counttimes.Precondition
countmust be non-negative integer.Declaration
Swift
public func retry(upTo count: Int) -> SignalProducer<Value, Error>Parameters
countNumber of retries.
Return Value
A signal producer that restarts up to
counttimes. -
Wait for completion of
self, then forward all events fromreplacement. Any failure or interruption sent fromselfis forwarded immediately, in which casereplacementwill not be started, and none of its events will be be forwarded.Note
All values sent from
selfare ignored.Declaration
Swift
public func then<U>(_ replacement: SignalProducer<U, Error>) -> SignalProducer<U, Error>Parameters
replacementA producer to start when
selfcompletes.Return Value
A producer that sends events from
selfand then fromreplacementwhenselfcompletes. -
Wait for completion of
self, then forward all events fromreplacement. Any failure or interruption sent fromselfis forwarded immediately, in which casereplacementwill not be started, and none of its events will be be forwarded.Note
All values sent from
selfare ignored.Declaration
Swift
public func then<U>(_ replacement: SignalProducer<U, NoError>) -> SignalProducer<U, Error>Parameters
replacementA producer to start when
selfcompletes.Return Value
A producer that sends events from
selfand then fromreplacementwhenselfcompletes. -
Start the producer, then block, waiting for the first value.
When a single value or error is sent, the returned
Resultwill represent those cases. However, when no values are sent,nilwill be returned.Declaration
Swift
public func first() -> Result<Value, Error>?Return Value
Result when single
valueorfailedevent is received.nilwhen no events are received. -
Start the producer, then block, waiting for events:
valueandcompleted.When a single value or error is sent, the returned
Resultwill represent those cases. However, when no values are sent, or when more than one value is sent,nilwill be returned.Declaration
Swift
public func single() -> Result<Value, Error>?Return Value
Result when single
valueorfailedevent is received.nilwhen 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
Resultwill represent those cases. However, when no values are sent,nilwill be returned.Declaration
Swift
public func last() -> Result<Value, Error>?Return Value
Result when single
valueorfailedevent is received.nilwhen no events are received. -
Starts the producer, then blocks, waiting for completion.
When a completion or error is sent, the returned
Resultwill represent those cases.Declaration
Swift
public func wait() -> Result<(), Error>Return Value
Result when single
completionorfailedevent is received. -
Creates a new
SignalProducerthat will multicast values emitted by the underlying producer, up tocapacity. This means that all clients of thisSignalProducerwill see the same version of the emitted values/errors.The underlying
SignalProducerwill not be started untilselfis started for the first time. When subscribing to this producer, all previous values (up tocapacity) will be emitted, followed by any new values.If you find yourself needing the current value (the last buffered value) you should consider using
PropertyTypeinstead, 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 likePropertyType, or representing your stream using aSignalinstead.This operator is only recommended when you absolutely need to introduce a layer of caching in front of another
SignalProducer.Precondition
capacitymust be non-negative integer.Declaration
Swift
public func replayLazily(upTo capacity: Int) -> SignalProducer<Value, Error>Parameters
capacityNumber of values to hold.
Return Value
A caching producer that will hold up to last
capacityvalues. -
concatsnextontoself.Declaration
Swift
public func concat(_ next: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>Parameters
nextA follow-up producer to concat
selfwith.Return Value
A producer that will start
selfand then on completion ofself- will startnext. -
concatsvalueontoself.Declaration
Swift
public func concat(value: Value) -> SignalProducer<Value, Error>Parameters
valueA value to concat onto
self.Return Value
A producer that, when started, will emit own values and on completion will emit a
value. -
concatsselfonto initialprevious.Declaration
Swift
public func prefix(_ previous: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>Parameters
previousA producer to start before
self.Return Value
A signal producer that, when started, first emits values from
previousproducer and then fromself. -
concatsselfonto initialvalue.Declaration
Swift
public func prefix(value: Value) -> SignalProducer<Value, Error>Parameters
valueA first value to emit.
Return Value
A producer that, when started, first emits
value, then all values emited byself. -
Merges the given producers into a single
SignalProducerthat will emit all values from each of them, and complete when all of them have completed.Declaration
Swift
public static func merge<Seq: Sequence>(_ producers: Seq) -> SignalProducer<Value, Error> where Seq.Iterator.Element == SignalProducer<Value, Error>Parameters
producersA sequence of producers to merge.
-
Merges the given producers into a single
SignalProducerthat will emit all values from each of them, and complete when all of them have completed.Declaration
Swift
public static func merge(_ producers: SignalProducer<Value, Error>...) -> SignalProducer<Value, Error>Parameters
producersA sequence of producers to merge.
-
Maps each event from
selfto a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.Warning
If
selfor 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
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal producer with transformed value. -
Maps each event from
selfto a new producer, then flattens the resulting producers (into a producer of values), according to the semantics of the given strategy.Warning
If
selffails, 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
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal producer with transformed value. -
Maps each event from
selfto a new producer, then flattens the resulting signals (into a producer of values), according to the semantics of the given strategy.Warning
If
selfor any of the created signals emit an error, the returned producer will forward that error immediately.Declaration
Swift
public func flatMap<U>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> Signal<U, Error>) -> SignalProducer<U, Error>Parameters
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal with transformed value. -
Maps each event from
selfto a new producer, then flattens the resulting signals (into a producer of values), according to the semantics of the given strategy.Warning
If
selfemits an error, the returned producer will forward that error immediately.Declaration
Swift
public func flatMap<U>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> Signal<U, NoError>) -> SignalProducer<U, Error>Parameters
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal with transformed value. -
Maps each event from
selfto a new property, then flattens the resulting properties (into a producer of values), according to the semantics of the given strategy.Warning
If
selfemits an error, the returned producer will forward that error immediately.Declaration
Swift
public func flatMap<P: PropertyProtocol>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> P) -> SignalProducer<P.Value, Error>Parameters
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a property 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>(_ handler: @escaping (Error) -> SignalProducer<Value, F>) -> SignalProducer<Value, F>Parameters
handlerA 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.SignalProducer> = LoggingEvent.SignalProducer.allEvents, fileName: String = #file, functionName: String = #function, lineNumber: Int = #line, logger: @escaping EventLogger = defaultEventLog ) -> SignalProducer<Value, Error>Parameters
identifiera string to identify the SignalProducer firing events.
eventsTypes of events to log.
fileNameName of the file containing the code which fired the event.
functionNameFunction where event was fired.
lineNumberLine number where event was fired.
loggerLogger that logs the events.
Return Value
Signal producer that, when started, logs the fired events.
-
Observe the binding source by sending any events to the given observer.
Declaration
Swift
public func observe(_ observer: ProducedSignal.Observer, during lifetime: Lifetime) -> Disposable?
-
Flattens the inner producers sent upon
producer(into a single producer of values), according to the semantics of the given strategy.Note
If
produceror an active inner producer fails, the returned producer will forward that failure immediately.Warning
interruptedevents on inner producers will be treated likecompletedevents on inner producers.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Error>Parameters
strategyStrategy 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
interruptedevents on inner producers will be treated likecompletedevents on inner producers.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Value.Error>Parameters
strategyStrategy 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
interruptedevents on inner producers will be treated likecompletedevents on inner producers.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Value.Error>Parameters
strategyStrategy 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
signalfails, the returned signal will forward that failure immediately.Warning
interruptedevents on inner producers will be treated likecompletedevents on inner producers.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Error>Parameters
strategyStrategy used when flattening signals.
-
Flattens the inner signals sent upon
producer(into a single producer of values), according to the semantics of the given strategy.Note
If
produceror an active inner signal emits an error, the returned producer will forward that error immediately.Warning
interruptedevents on inner signals will be treated likecompletedevents on inner signals.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Error>Parameters
strategyStrategy used when flattening signals.
-
Flattens the inner signals sent upon
producer(into a single producer of values), according to the semantics of the given strategy.Note
If an active inner signal emits an error, the returned producer will forward that error immediately.
Warning
interruptedevents on inner signals will be treated likecompletedevents on inner signals.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Value.Error>Parameters
strategyStrategy used when flattening signals.
-
Flattens the inner signals sent upon
producer(into a single producer of values), according to the semantics of the given strategy.Warning
interruptedevents on inner signals will be treated likecompletedevents on inner signals.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Value.Error>Parameters
strategyStrategy used when flattening signals.
-
Flattens the inner signals sent upon
producer(into a single producer of values), according to the semantics of the given strategy.Note
If
produceremits an error, the returned producer will forward that error immediately.Warning
interruptedevents on inner signals will be treated likecompletedevents on inner signals.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Error>Parameters
strategyStrategy used when flattening signals.
-
Flattens the
sequencevalue sent bysignal.Declaration
Swift
public func flatten() -> SignalProducer<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
signalfails, the returned signal will forward that failure immediately.Declaration
Swift
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Value, Error>Parameters
strategyStrategy used when flattening signals.
-
Maps each event from
selfto 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, E>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> SignalProducer<U, E>) -> SignalProducer<U, E>Parameters
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal producer with transformed value. -
Maps each event from
selfto 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, NoError>) -> SignalProducer<U, NoError>Parameters
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal producer with transformed value. -
Maps each event from
selfto a new producer, then flattens the resulting signals (into a producer of values), according to the semantics of the given strategy.Warning
If any of the created signals emit an error, the returned producer will forward that error immediately.
Declaration
Swift
public func flatMap<U, E>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> Signal<U, E>) -> SignalProducer<U, E>Parameters
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal with transformed value. -
Maps each event from
selfto a new producer, then flattens the resulting signals (into a producer of values), according to the semantics of the given strategy.Declaration
Swift
public func flatMap<U>(_ strategy: FlattenStrategy, transform: @escaping (Value) -> Signal<U, NoError>) -> SignalProducer<U, NoError>Parameters
strategyStrategy used when flattening signals.
transformA closure that takes a value emitted by
selfand returns a signal with transformed value. -
Create a Signal from the producer, then add exactly one observer to the Signal, which will invoke the given callback when
valueevents are received.Declaration
Swift
public func startWithValues(_ value: @escaping (Value) -> Void) -> DisposableParameters
valueA closure that accepts a value carried by
valueevent.Return Value
A
Disposablewhich can be used to interrupt the work associated with the Signal, and prevent any future callbacks from being invoked. -
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 promoteErrors<F: Swift.Error>(_: F.Type) -> SignalProducer<Value, F>Parameters
_An
ErrorType.Return Value
A producer that has an instantiatable
ErrorType. -
Forward events from
selfuntilinterval. Then if producer isn’t completed yet, fails witherroronscheduler.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: Swift.Error>( after interval: TimeInterval, raising error: NewError, on scheduler: DateScheduler ) -> SignalProducer<Value, NewError>Parameters
intervalNumber of seconds to wait for
selfto complete.errorError to send with
failedevent ifselfis not completed whenintervalpasses.scheudlerA scheduler to deliver error on.
Return Value
A producer that sends events for at most
intervalseconds, then, if notcompleted- sendserrorwithfailedevent onscheduler. -
Apply a failable
operationto values fromselfwith successful results forwarded on the returned producer and thrown errors sent as failed events.Declaration
Swift
public func attempt(_ operation: @escaping (Value) throws -> Void) -> SignalProducer<Value, AnyError>Parameters
operationA failable closure that accepts a value.
Return Value
A producer that forwards successes as
valueevents and thrown errors asfailedevents. -
Apply a failable
operationto values fromselfwith successful results mapped on the returned producer and thrown errors sent as failed events.Declaration
Swift
public func attemptMap<U>(_ operation: @escaping (Value) throws -> U) -> SignalProducer<U, AnyError>Parameters
operationA failable closure that accepts a value and attempts to transform it.
Return Value
A producer that sends successfully mapped values from
self, or thrown errors asfailedevents. -
Wait for completion of
self, then forward all events fromreplacement.Note
All values sent from
selfare ignored.Declaration
Swift
public func then<U, NewError: Swift.Error>(_ replacement: SignalProducer<U, NewError>) -> SignalProducer<U, NewError>Parameters
replacementA producer to start when
selfcompletes.Return Value
A producer that sends events from
selfand then fromreplacementwhenselfcompletes.
-
Unwraps non-
nilvalues and forwards them on the returned signal,nilvalues 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
Eventvalues 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
selfevents.
-
Create a
SignalProducerthat will attempt the given failable operation once for each invocation ofstart().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 static func attempt(_ operation: @escaping () throws -> Value) -> SignalProducer<Value, AnyError>Parameters
operationA failable closure.
Return Value
A
SignalProducerthat will forward a success as avalueevent and then complete orfailedevent if the closure throws. -
Apply a failable
operationto values fromselfwith successful results forwarded on the returned producer and thrown errors sent as failed events.Declaration
Swift
public func attempt(_ operation: @escaping (Value) throws -> Void) -> SignalProducer<Value, AnyError>Parameters
operationA failable closure that accepts a value.
Return Value
A producer that forwards successes as
valueevents and thrown errors asfailedevents. -
Apply a failable
operationto values fromselfwith successful results mapped on the returned producer and thrown errors sent as failed events.Declaration
Swift
public func attemptMap<U>(_ operation: @escaping (Value) throws -> U) -> SignalProducer<U, AnyError>Parameters
operationA failable closure that accepts a value and attempts to transform it.
Return Value
A producer that sends successfully mapped values from
self, or thrown errors asfailedevents.
-
Forward only those values from
selfwhich are not duplicates of the immedately preceding value.Note
The first value is always forwarded.
Declaration
Swift
public func skipRepeats() -> SignalProducer<Value, Error>Return Value
A producer that does not send two equal values sequentially.
-
Forward only those values from
selfthat 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.
-
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
selfandproducer.Declaration
Swift
public func and(_ producer: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>Parameters
producerProducer 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
selfandsignal.Declaration
Swift
public func and(_ signal: Signal<Value, Error>) -> SignalProducer<Value, Error>Parameters
signalSignal 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
selfandproducer.Declaration
Swift
public func or(_ producer: SignalProducer<Value, Error>) -> SignalProducer<Value, Error>Parameters
producerProducer 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
selfandsignal.Declaration
Swift
public func or(_ signal: Signal<Value, Error>) -> SignalProducer<Value, Error>Parameters
signalSignal to be combined with
self.Return Value
A producer that emits the logical OR results.
View on GitHub
Install in Dash
SignalProducer Struct Reference