ObservableType
public protocol ObservableType : ObservableConvertibleType
Represents a push style sequence.
-
subscribe(_:)Default implementationSubscribes
observerto receive events for this sequence.Grammar
Next* (Error | Completed)?
- sequences can produce zero or more elements so zero or more
Nextevents can be sent toobserver - once an
ErrororCompletedevent is sent, the sequence terminates and can’t produce any other elements
It is possible that events are sent from different threads, but no two events can be sent concurrently to
observer.Resource Management
When sequence sends
CompleteorErrorevent all internal resources that compute sequence elements will be freed.To cancel production of sequence elements and free resources immediatelly, call
disposeon returned subscription.Default Implementation
Subscribes an event handler to an observable sequence.
Declaration
Swift
func subscribe<O: ObserverType where O.E == E>(observer: O) -> DisposableReturn Value
Subscription for
observerthat can be used to cancel production of sequence elements and free resources. - sequences can produce zero or more elements so zero or more
-
Type of elements in sequence.
Declaration
Swift
associatedtype E
-
throttle(_:scheduler:)Extension methodIgnores elements from an observable sequence which are followed by another element within a specified relative time duration, using the specified scheduler to run throttling timers.
throttleanddebounceare synonyms.Declaration
Swift
public func throttle(dueTime: RxTimeInterval, scheduler: SchedulerType) -> Observable<E>Parameters
dueTimeThrottling duration for each element.
schedulerScheduler to run the throttle timers and send events on.
Return Value
The throttled sequence.
-
debounce(_:scheduler:)Extension methodIgnores elements from an observable sequence which are followed by another element within a specified relative time duration, using the specified scheduler to run throttling timers.
throttleanddebounceare synonyms.Declaration
Swift
public func debounce(dueTime: RxTimeInterval, scheduler: SchedulerType) -> Observable<E>Parameters
dueTimeThrottling duration for each element.
schedulerScheduler to run the throttle timers and send events on.
Return Value
The throttled sequence.
-
sample(_:)Extension methodSamples the source observable sequence using a samper observable sequence producing sampling ticks.
Upon each sampling tick, the latest element (if any) in the source sequence during the last sampling interval is sent to the resulting sequence.
In case there were no new elements between sampler ticks, no element is sent to the resulting sequence.
Seealso
Declaration
Swift
public func sample<O: ObservableType>(sampler: O) -> Observable<E>Parameters
samplerSampling tick sequence.
Return Value
Sampled observable sequence.
-
take(_:scheduler:)Extension methodTakes elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
Seealso
Declaration
Swift
public func take(duration: RxTimeInterval, scheduler: SchedulerType) -> Observable<E>Parameters
durationDuration for taking elements from the start of the sequence.
schedulerScheduler to run the timer on.
Return Value
An observable sequence with the elements taken during the specified duration from the start of the source sequence.
-
skip(_:scheduler:)Extension methodSkips elements for the specified duration from the start of the observable source sequence, using the specified scheduler to run timers.
Seealso
Declaration
Swift
public func skip(duration: RxTimeInterval, scheduler: SchedulerType) -> Observable<E>Parameters
durationDuration for skipping elements from the start of the sequence.
schedulerScheduler to run the timer on.
Return Value
An observable sequence with the elements skipped during the specified duration from the start of the source sequence.
-
ignoreElements()Extension methodSkips elements and completes (or errors) when the receiver completes (or errors). Equivalent to filter that always returns false.
Declaration
Swift
public func ignoreElements() -> Observable<E>Return Value
An observable sequence that skips all elements of the source sequence.
-
delaySubscription(_:scheduler:)Extension methodTime shifts the observable sequence by delaying the subscription with the specified relative time duration, using the specified scheduler to run timers.
Seealso
Declaration
Swift
public func delaySubscription(dueTime: RxTimeInterval, scheduler: SchedulerType) -> Observable<E>Parameters
dueTimeRelative time shift of the subscription.
schedulerScheduler to run the subscription delay timer on.
Return Value
Time-shifted sequence.
-
buffer(timeSpan:count:scheduler:)Extension methodProjects each element of an observable sequence into a buffer that’s sent out when either it’s full or a given amount of time has elapsed, using the specified scheduler to run timers.
A useful real-world analogy of this overload is the behavior of a ferry leaving the dock when all seats are taken, or at the scheduled time of departure, whichever event occurs first.
Seealso
Declaration
Swift
public func buffer(timeSpan timeSpan: RxTimeInterval, count: Int, scheduler: SchedulerType) -> Observable<[E]>Parameters
timeSpanMaximum time length of a buffer.
countMaximum element count of a buffer.
schedulerScheduler to run buffering timers on.
Return Value
An observable sequence of buffers.
-
window(timeSpan:count:scheduler:)Extension methodProjects each element of an observable sequence into a window that is completed when either it’s full or a given amount of time has elapsed.
Seealso
Declaration
Swift
public func window(timeSpan timeSpan: RxTimeInterval, count: Int, scheduler: SchedulerType) -> Observable<Observable<E>>Parameters
timeSpanMaximum time length of a window.
countMaximum element count of a window.
schedulerScheduler to run windowing timers on.
Return Value
An observable sequence of windows (instances of
Observable).
-
timeout(_:scheduler:)Extension methodApplies a timeout policy for each element in the observable sequence. If the next element isn’t received within the specified timeout duration starting from its predecessor, a TimeoutError is propagated to the observer.
Seealso
Declaration
Swift
public func timeout(dueTime: RxTimeInterval, scheduler: SchedulerType) -> Observable<E>Parameters
dueTimeMaximum duration between values before a timeout occurs.
schedulerScheduler to run the timeout timer on.
Return Value
An observable sequence with a TimeoutError in case of a timeout.
-
timeout(_:other:scheduler:)Extension methodApplies a timeout policy for each element in the observable sequence, using the specified scheduler to run timeout timers. If the next element isn’t received within the specified timeout duration starting from its predecessor, the other observable sequence is used to produce future messages from that point on.
Seealso
Declaration
Swift
public func timeout<O: ObservableConvertibleType where E == O.E>(dueTime: RxTimeInterval, other: O, scheduler: SchedulerType) -> Observable<E>Parameters
dueTimeMaximum duration between values before a timeout occurs.
otherSequence to return in case of a timeout.
schedulerScheduler to run the timeout timer on.
Return Value
The source sequence switching to the other sequence in case of a timeout.
-
subscribe(onNext:onError:onCompleted:onDisposed:)Extension methodSubscribes an element handler, an error handler, a completion handler and disposed handler to an observable sequence.
Declaration
Swift
public func subscribe(onNext onNext: (E -> Void)? = nil, onError: (ErrorType -> Void)? = nil, onCompleted: (() -> Void)? = nil, onDisposed: (() -> Void)? = nil) -> DisposableParameters
onNextAction to invoke for each element in the observable sequence.
onErrorAction to invoke upon errored termination of the observable sequence.
onCompletedAction to invoke upon graceful termination of the observable sequence.
onDisposedAction to invoke upon any type of termination of sequence (if the sequence has gracefully completed, errored, or if the generation is cancelled by disposing subscription).
Return Value
Subscription object used to unsubscribe from the observable sequence.
-
subscribeNext(_:)Extension methodSubscribes an element handler to an observable sequence.
Declaration
Swift
public func subscribeNext(onNext: (E) -> Void) -> DisposableParameters
onNextAction to invoke for each element in the observable sequence.
Return Value
Subscription object used to unsubscribe from the observable sequence.
-
subscribeError(_:)Extension methodSubscribes an error handler to an observable sequence.
Declaration
Swift
public func subscribeError(onError: (ErrorType) -> Void) -> DisposableParameters
onErrorAction to invoke upon errored termination of the observable sequence.
Return Value
Subscription object used to unsubscribe from the observable sequence.
-
subscribeCompleted(_:)Extension methodSubscribes a completion handler to an observable sequence.
Declaration
Swift
public func subscribeCompleted(onCompleted: () -> Void) -> DisposableParameters
onCompletedAction to invoke upon graceful termination of the observable sequence.
Return Value
Subscription object used to unsubscribe from the observable sequence.
-
subscribeSafe(_:)Extension methodAll internal subscribe calls go through this method.
Declaration
Swift
func subscribeSafe<O: ObserverType where O.E == E>(observer: O) -> Disposable
-
switchLatest()Extension methodTransforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
Each time a new inner observable sequence is received, unsubscribe from the previous inner observable sequence.
Seealso
Declaration
Swift
public func switchLatest() -> Observable<E.E>Return Value
The observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.
-
concat(_:)Extension methodConcatenates the second observable sequence to
selfupon successful termination ofself.Seealso
Declaration
Swift
public func concat<O: ObservableConvertibleType where O.E == E>(second: O) -> Observable<E>Parameters
secondSecond observable sequence.
Return Value
An observable sequence that contains the elements of
self, followed by those of the second sequence.
-
concat()Extension methodConcatenates all inner observable sequences, as long as the previous observable sequence terminated successfully.
Seealso
Declaration
Swift
public func concat() -> Observable<E.E>Return Value
An observable sequence that contains the elements of each observed inner sequence, in sequential order.
-
merge()Extension methodMerges elements from all observable sequences in the given enumerable sequence into a single observable sequence.
Seealso
Declaration
Swift
public func merge() -> Observable<E.E>Return Value
The observable sequence that merges the elements of the observable sequences.
-
merge(maxConcurrent:)Extension methodMerges elements from all inner observable sequences into a single observable sequence, limiting the number of concurrent subscriptions to inner sequences.
Seealso
Declaration
Swift
public func merge(maxConcurrent maxConcurrent: Int) -> Observable<E.E>Parameters
maxConcurrentMaximum number of inner observable sequences being subscribed to concurrently.
Return Value
The observable sequence that merges the elements of the inner sequences.
-
catchError(_:)Extension methodContinues an observable sequence that is terminated by an error with the observable sequence produced by the handler.
Seealso
Declaration
Swift
public func catchError(handler: (ErrorType) throws -> Observable<E>) -> Observable<E>Parameters
handlerError handler function, producing another observable sequence.
Return Value
An observable sequence containing the source sequence’s elements, followed by the elements produced by the handler’s resulting observable sequence in case an error occurred.
-
catchErrorJustReturn(_:)Extension methodContinues an observable sequence that is terminated by an error with a single element.
Seealso
Declaration
Swift
public func catchErrorJustReturn(element: E) -> Observable<E>Parameters
elementLast element in an observable sequence in case error occurs.
Return Value
An observable sequence containing the source sequence’s elements, followed by the
elementin case an error occurred.
-
takeUntil(_:)Extension methodReturns the elements from the source observable sequence until the other observable sequence produces an element.
Declaration
Swift
public func takeUntil<O: ObservableType>(other: O) -> Observable<E>Parameters
otherObservable sequence that terminates propagation of elements of the source sequence.
Return Value
An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
-
skipUntil(_:)Extension methodReturns the elements from the source observable sequence that are emitted after the other observable sequence produces an element.
Declaration
Swift
public func skipUntil<O: ObservableType>(other: O) -> Observable<E>Parameters
otherObservable sequence that starts propagation of elements of the source sequence.
Return Value
An observable sequence containing the elements of the source sequence that are emitted after the other sequence emits an item.
-
amb(_:)Extension methodPropagates the observable sequence that reacts first.
Seealso
Declaration
Swift
public func amb<O2: ObservableType where O2.E == E> (right: O2) -> Observable<E>Parameters
rightSecond observable sequence.
Return Value
An observable sequence that surfaces either of the given sequences, whichever reacted first.
-
withLatestFrom(_:resultSelector:)Extension methodMerges two observable sequences into one observable sequence by combining each element from self with the latest element from the second source, if any.
Declaration
Swift
public func withLatestFrom<SecondO: ObservableConvertibleType, ResultType>(second: SecondO, resultSelector: (E, SecondO.E) throws -> ResultType) -> Observable<ResultType>Parameters
secondSecond observable source.
resultSelectorFunction to invoke for each element from the self combined with the latest element from the second source, if any.
Return Value
An observable sequence containing the result of combining each element of the self with the latest element from the second source, if any, using the specified result selector function.
-
withLatestFrom(_:)Extension methodMerges two observable sequences into one observable sequence by using latest element from the second sequence every time when
selfemitts an element.Declaration
Swift
public func withLatestFrom<SecondO: ObservableConvertibleType>(second: SecondO) -> Observable<SecondO.E>Parameters
secondSecond observable source.
Return Value
An observable sequence containing the result of combining each element of the self with the latest element from the second source, if any, using the specified result selector function.
-
filter(_:)Extension methodFilters the elements of an observable sequence based on a predicate.
Seealso
Declaration
Swift
public func filter(predicate: (E) throws -> Bool) -> Observable<E>Parameters
predicateA function to test each source element for a condition.
Return Value
An observable sequence that contains elements from the input sequence that satisfy the condition.
-
takeWhile(_:)Extension methodReturns elements from an observable sequence as long as a specified condition is true.
Declaration
Swift
public func takeWhile(predicate: (E) throws -> Bool) -> Observable<E>Parameters
predicateA function to test each element for a condition.
Return Value
An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
-
takeWhileWithIndex(_:)Extension methodReturns elements from an observable sequence as long as a specified condition is true.
The element’s index is used in the logic of the predicate function.
Declaration
Swift
public func takeWhileWithIndex(predicate: (E, Int) throws -> Bool) -> Observable<E>Parameters
predicateA function to test each element for a condition; the second parameter of the function represents the index of the source element.
Return Value
An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
-
take(_:)Extension methodReturns a specified number of contiguous elements from the start of an observable sequence.
Seealso
Declaration
Swift
public func take(count: Int) -> Observable<E>Parameters
countThe number of elements to return.
Return Value
An observable sequence that contains the specified number of elements from the start of the input sequence.
-
takeLast(_:)Extension methodReturns a specified number of contiguous elements from the end of an observable sequence.
This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.
Declaration
Swift
public func takeLast(count: Int) -> Observable<E>Parameters
countNumber of elements to take from the end of the source sequence.
Return Value
An observable sequence containing the specified number of elements from the end of the source sequence.
-
skip(_:)Extension methodBypasses a specified number of elements in an observable sequence and then returns the remaining elements.
Seealso
Declaration
Swift
public func skip(count: Int) -> Observable<E>Parameters
countThe number of elements to skip before returning the remaining elements.
Return Value
An observable sequence that contains the elements that occur after the specified index in the input sequence.
-
skipWhile(_:)Extension methodBypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
Declaration
Swift
public func skipWhile(predicate: (E) throws -> Bool) -> Observable<E>Parameters
predicateA function to test each element for a condition.
Return Value
An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
-
skipWhileWithIndex(_:)Extension methodBypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements. The element’s index is used in the logic of the predicate function.
Declaration
Swift
public func skipWhileWithIndex(predicate: (E, Int) throws -> Bool) -> Observable<E>Parameters
predicateA function to test each element for a condition; the second parameter of the function represents the index of the source element.
Return Value
An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
-
map(_:)Extension methodProjects each element of an observable sequence into a new form.
Seealso
Declaration
Swift
public func map<R>(selector: E throws -> R) -> Observable<R>Parameters
selectorA transform function to apply to each source element.
Return Value
An observable sequence whose elements are the result of invoking the transform function on each element of source.
-
mapWithIndex(_:)Extension methodProjects each element of an observable sequence into a new form by incorporating the element’s index.
Seealso
Declaration
Swift
public func mapWithIndex<R>(selector: (E, Int) throws -> R) -> Observable<R>Parameters
selectorA transform function to apply to each source element; the second parameter of the function represents the index of the source element.
Return Value
An observable sequence whose elements are the result of invoking the transform function on each element of source.
-
flatMap(_:)Extension methodProjects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
Seealso
Declaration
Swift
public func flatMap<O: ObservableConvertibleType>(selector: (E) throws -> O) -> Observable<O.E>Parameters
selectorA transform function to apply to each element.
Return Value
An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.
-
flatMapWithIndex(_:)Extension methodProjects each element of an observable sequence to an observable sequence by incorporating the element’s index and merges the resulting observable sequences into one observable sequence.
Seealso
Declaration
Swift
public func flatMapWithIndex<O: ObservableConvertibleType>(selector: (E, Int) throws -> O) -> Observable<O.E>Parameters
selectorA transform function to apply to each element; the second parameter of the function represents the index of the source element.
Return Value
An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.
-
flatMapFirst(_:)Extension methodProjects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence. If element is received while there is some projected observable sequence being merged it will simply be ignored.
Declaration
Swift
public func flatMapFirst<O: ObservableConvertibleType>(selector: (E) throws -> O) -> Observable<O.E>Parameters
selectorA transform function to apply to element that was observed while no observable is executing in parallel.
Return Value
An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence that was received while no other sequence was being calculated.
-
flatMapLatest(_:)Extension methodProjects each element of an observable sequence into a new sequence of observable sequences and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
It is a combination of
map+switchLatestoperatorDeclaration
Swift
public func flatMapLatest<O: ObservableConvertibleType>(selector: (E) throws -> O) -> Observable<O.E>Parameters
selectorA transform function to apply to each element.
Return Value
An observable sequence whose elements are the result of invoking the transform function on each element of source producing an Observable of Observable sequences and that at any point in time produces the elements of the most recent inner observable sequence that has been received.
-
elementAt(_:)Extension methodReturns a sequence emitting only item n emitted by an Observable
Declaration
Swift
public func elementAt(index: Int) -> Observable<E>Parameters
indexThe index of the required item (starting from 0).
Return Value
An observable sequence that emits the desired item as its own sole emission.
-
single()Extension methodThe single operator is similar to first, but throws a
RxError.NoElementsorRxError.MoreThanOneElementif the source Observable does not emit exactly one item before successfully completing.Seealso
Declaration
Swift
public func single() -> Observable<E>Return Value
An observable sequence that emits a single item or throws an exception if more (or none) of them are emitted.
-
single(_:)Extension methodThe single operator is similar to first, but throws a
RxError.NoElementsorRxError.MoreThanOneElementif the source Observable does not emit exactly one item before successfully completing.Seealso
Declaration
Swift
public func single(predicate: (E) throws -> Bool) -> Observable<E>Parameters
predicateA function to test each source element for a condition.
Return Value
An observable sequence that emits a single item or throws an exception if more (or none) of them are emitted.
-
multicast(_:)Extension methodMulticasts the source sequence notifications through the specified subject to the resulting connectable observable.
Upon connection of the connectable observable, the subject is subscribed to the source exactly one, and messages are forwarded to the observers registered with the connectable observable.
For specializations with fixed subject types, see
publishandreplay.Declaration
Swift
public func multicast<S: SubjectType where S.SubjectObserverType.E == E>(subject: S) -> ConnectableObservable<S.E>Parameters
subjectSubject to push source elements into.
Return Value
A connectable observable sequence that upon connection causes the source sequence to push results into the specified subject.
-
multicast(_:selector:)Extension methodMulticasts the source sequence notifications through an instantiated subject into all uses of the sequence within a selector function.
Each subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the selector function’s invocation.
For specializations with fixed subject types, see
publishandreplay.Declaration
Swift
public func multicast<S: SubjectType, R where S.SubjectObserverType.E == E>(subjectSelector: () throws -> S, selector: (Observable<S.E>) throws -> Observable<R>) -> Observable<R>Parameters
subjectSelectorFactory function to create an intermediate subject through which the source sequence’s elements will be multicast to the selector function.
selectorSelector function which can use the multicasted source sequence subject to the policies enforced by the created subject.
Return Value
An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.
-
publish()Extension methodReturns a connectable observable sequence that shares a single subscription to the underlying sequence.
This operator is a specialization of
multicastusing aPublishSubject.Seealso
Declaration
Swift
public func publish() -> ConnectableObservable<E>Return Value
A connectable observable sequence that shares a single subscription to the underlying sequence.
-
replay(_:)Extension methodReturns a connectable observable sequence that shares a single subscription to the underlying sequence replaying bufferSize elements.
This operator is a specialization of
multicastusing aReplaySubject.Seealso
Declaration
Swift
public func replay(bufferSize: Int) -> ConnectableObservable<E>Parameters
bufferSizeMaximum element count of the replay buffer.
Return Value
A connectable observable sequence that shares a single subscription to the underlying sequence.
-
replayAll()Extension methodReturns a connectable observable sequence that shares a single subscription to the underlying sequence replaying all elements.
This operator is a specialization of
multicastusing aReplaySubject.Seealso
Declaration
Swift
public func replayAll() -> ConnectableObservable<E>Return Value
A connectable observable sequence that shares a single subscription to the underlying sequence.
-
share()Extension methodReturns an observable sequence that shares a single subscription to the underlying sequence.
This operator is a specialization of publish which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
Seealso
Declaration
Swift
public func share() -> Observable<E>Return Value
An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
-
shareReplay(_:)Extension methodReturns an observable sequence that shares a single subscription to the underlying sequence, and immediately upon subscription replays maximum number of elements in buffer.
This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
Declaration
Swift
public func shareReplay(bufferSize: Int) -> Observable<E>Parameters
bufferSizeMaximum element count of the replay buffer.
Return Value
An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
-
shareReplayLatestWhileConnected()Extension methodReturns an observable sequence that shares a single subscription to the underlying sequence, and immediately upon subscription replays latest element in buffer.
This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
Unlike
shareReplay(bufferSize: Int), this operator will clear latest element from replay buffer in case number of subscribers drops from one to zero. In case sequence completes or errors out replay buffer is also cleared.Declaration
Swift
public func shareReplayLatestWhileConnected() -> Observable<E>Return Value
An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
-
debug(_:file:line:function:)Extension methodPrints received events for all observers on standard output.
Seealso
Declaration
Swift
public func debug(identifier: String? = nil, file: String = #file, line: UInt = #line, function: String = #function) -> Observable<E>Parameters
identifierIdentifier that is printed together with event description to standard output.
Return Value
An observable sequence whose events are printed to standard output.
-
observeOn(_:)Extension methodWraps the source sequence in order to run its observer callbacks on the specified scheduler.
This only invokes observer callbacks on a
scheduler. In case the subscription and/or unsubscription actions have side-effects that require to be run on a scheduler, usesubscribeOn.Declaration
Swift
public func observeOn(scheduler: ImmediateSchedulerType) -> Observable<E>Parameters
schedulerScheduler to notify observers on.
Return Value
The source sequence whose observations happen on the specified scheduler.
-
subscribeOn(_:)Extension methodWraps the source sequence in order to run its subscription and unsubscription logic on the specified scheduler.
This operation is not commonly used.
This only performs the side-effects of subscription and unsubscription on the specified scheduler.
In order to invoke observer callbacks on a
scheduler, useobserveOn.Declaration
Swift
public func subscribeOn(scheduler: ImmediateSchedulerType) -> Observable<E>Parameters
schedulerScheduler to perform subscription and unsubscription actions on.
Return Value
The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.
-
asObservable()Extension methodDefault implementation of converting
ObservableTypetoObservable.Declaration
Swift
public func asObservable() -> Observable<E>
-
reduce(_:accumulator:mapResult:)Extension methodApplies an
accumulatorfunction over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specifiedseedvalue is used as the initial accumulator value.For aggregation behavior with incremental intermediate results, see
scan.Seealso
Declaration
Swift
public func reduce<A, R>(seed: A, accumulator: (A, E) throws -> A, mapResult: (A) throws -> R) -> Observable<R>Parameters
seedThe initial accumulator value.
accumulatorA accumulator function to be invoked on each element.
mapResultA function to transform the final accumulator value into the result value.
Return Value
An observable sequence containing a single element with the final accumulator value.
-
reduce(_:accumulator:)Extension methodApplies an
accumulatorfunction over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specifiedseedvalue is used as the initial accumulator value.For aggregation behavior with incremental intermediate results, see
scan.Seealso
Declaration
Swift
public func reduce<A>(seed: A, accumulator: (A, E) throws -> A) -> Observable<A>Parameters
seedThe initial accumulator value.
accumulatorA accumulator function to be invoked on each element.
Return Value
An observable sequence containing a single element with the final accumulator value.
-
toArray()Extension methodConverts an Observable into another Observable that emits the whole sequence as a single array and then terminates.
For aggregation behavior see
reduce.Seealso
Declaration
Swift
public func toArray() -> Observable<[E]>Return Value
An observable sequence containing all the emitted elements as array.
-
distinctUntilChanged()Extension methodReturns an observable sequence that contains only distinct contiguous elements according to equality operator.
Declaration
Swift
public func distinctUntilChanged() -> Observable<E>Return Value
An observable sequence only containing the distinct contiguous elements, based on equality operator, from the source sequence.
-
distinctUntilChanged(_:)Extension methodReturns an observable sequence that contains only distinct contiguous elements according to the
keySelector.Declaration
Swift
public func distinctUntilChanged<K: Equatable>(keySelector: (E) throws -> K) -> Observable<E>Parameters
keySelectorA function to compute the comparison key for each element.
Return Value
An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
-
distinctUntilChanged(_:)Extension methodReturns an observable sequence that contains only distinct contiguous elements according to the
comparer.Declaration
Swift
public func distinctUntilChanged(comparer: (lhs: E, rhs: E) throws -> Bool) -> Observable<E>Parameters
comparerEquality comparer for computed key values.
Return Value
An observable sequence only containing the distinct contiguous elements, based on
comparer, from the source sequence. -
distinctUntilChanged(_:comparer:)Extension methodReturns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer.
Declaration
Swift
public func distinctUntilChanged<K>(keySelector: (E) throws -> K, comparer: (lhs: K, rhs: K) throws -> Bool) -> Observable<E>Parameters
keySelectorA function to compute the comparison key for each element.
comparerEquality comparer for computed key values.
Return Value
An observable sequence only containing the distinct contiguous elements, based on a computed key value and the comparer, from the source sequence.
-
doOn(_:)Extension methodInvokes an action for each event in the observable sequence, and propagates all observer messages through the result sequence.
Seealso
Declaration
Swift
public func doOn(eventHandler: (Event<E>) throws -> Void) -> Observable<E>Parameters
eventHandlerAction to invoke for each event in the observable sequence.
Return Value
The source sequence with the side-effecting behavior applied.
-
doOn(onNext:onError:onCompleted:)Extension methodInvokes an action for each event in the observable sequence, and propagates all observer messages through the result sequence.
Seealso
Declaration
Swift
public func doOn(onNext onNext: (E throws -> Void)? = nil, onError: (ErrorType throws -> Void)? = nil, onCompleted: (() throws -> Void)? = nil) -> Observable<E>Parameters
onNextAction to invoke for each element in the observable sequence.
onErrorAction to invoke upon errored termination of the observable sequence.
onCompletedAction to invoke upon graceful termination of the observable sequence.
Return Value
The source sequence with the side-effecting behavior applied.
-
doOnNext(_:)Extension methodInvokes an action for each Next event in the observable sequence, and propagates all observer messages through the result sequence.
Declaration
Swift
public func doOnNext(onNext: (E throws -> Void)) -> Observable<E>Parameters
onNextAction to invoke for each element in the observable sequence.
Return Value
The source sequence with the side-effecting behavior applied.
-
doOnError(_:)Extension methodInvokes an action for the Error event in the observable sequence, and propagates all observer messages through the result sequence.
Declaration
Swift
public func doOnError(onError: (ErrorType throws -> Void)) -> Observable<E>Parameters
onErrorAction to invoke upon errored termination of the observable sequence.
Return Value
The source sequence with the side-effecting behavior applied.
-
doOnCompleted(_:)Extension methodInvokes an action for the Completed event in the observable sequence, and propagates all observer messages through the result sequence.
Declaration
Swift
public func doOnCompleted(onCompleted: (() throws -> Void)) -> Observable<E>Parameters
onCompletedAction to invoke upon graceful termination of the observable sequence.
Return Value
The source sequence with the side-effecting behavior applied.
-
startWith(_:)Extension methodPrepends a sequence of values to an observable sequence.
Declaration
Swift
public func startWith(elements: E ...) -> Observable<E>Parameters
elementsElements to prepend to the specified sequence.
Return Value
The source sequence prepended with the specified values.
-
retry()Extension methodRepeats the source observable sequence until it successfully terminates.
This could potentially create an infinite sequence.
Seealso
Declaration
Swift
public func retry() -> Observable<E>Return Value
Observable sequence to repeat until it successfully terminates.
-
retry(_:)Extension methodRepeats the source observable sequence the specified number of times in case of an error or until it successfully terminates.
If you encounter an error and want it to retry once, then you must use
retry(2)Seealso
Declaration
Swift
public func retry(maxAttemptCount: Int) -> Observable<E>Parameters
maxAttemptCountMaximum number of times to repeat the sequence.
Return Value
An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.
-
retryWhen(_:)Extension methodRepeats the source observable sequence on error when the notifier emits a next value. If the source observable errors and the notifier completes, it will complete the source sequence.
Seealso
Declaration
Swift
public func retryWhen<TriggerObservable: ObservableType, Error: ErrorType>(notificationHandler: Observable<Error> -> TriggerObservable) -> Observable<E>Parameters
notificationHandlerA handler that is passed an observable sequence of errors raised by the source observable and returns and observable that either continues, completes or errors. This behavior is then applied to the source observable.
Return Value
An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully or is notified to error or complete.
-
retryWhen(_:)Extension methodRepeats the source observable sequence on error when the notifier emits a next value. If the source observable errors and the notifier completes, it will complete the source sequence.
Seealso
Declaration
Swift
public func retryWhen<TriggerObservable: ObservableType>(notificationHandler: Observable<ErrorType> -> TriggerObservable) -> Observable<E>Parameters
notificationHandlerA handler that is passed an observable sequence of errors raised by the source observable and returns and observable that either continues, completes or errors. This behavior is then applied to the source observable.
Return Value
An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully or is notified to error or complete.
-
scan(_:accumulator:)Extension methodApplies an accumulator function over an observable sequence and returns each intermediate result. The specified seed value is used as the initial accumulator value.
For aggregation behavior with no intermediate results, see
reduce.Seealso
Declaration
Swift
public func scan<A>(seed: A, accumulator: (A, E) throws -> A) -> Observable<A>Parameters
seedThe initial accumulator value.
accumulatorAn accumulator function to be invoked on each element.
Return Value
An observable sequence containing the accumulated values.
ObservableType Protocol Reference