final class PublishSubject[A] extends Subject[A, A]
A PublishSubject emits to a subscriber only those items that are
emitted by the source subsequent to the time of the subscription.
If the source terminates with an error, the PublishSubject will not emit any
items to subsequent subscribers, but will simply pass along the error
notification from the source Observable.
- Self Type
- PublishSubject[A]
- See also
- Alphabetic
- By Inheritance
- PublishSubject
- Subject
- Observer
- Observable
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
++[B >: A](other: Observable[B]): Observable[B]
Concatenates the source with another observable.
Concatenates the source with another observable.
Ordering of subscription is preserved, so the second observable starts only after the source observable is completed successfully with an
onComplete. On the other hand, the second observable is never subscribed if the source completes with an error.- Definition Classes
- Observable
-
final
def
+:[B >: A](elem: B): Observable[B]
Creates a new Observable that emits the given element and then it also emits the events of the source (prepend operation).
Creates a new Observable that emits the given element and then it also emits the events of the source (prepend operation).
- Definition Classes
- Observable
-
final
def
:+[B >: A](elem: B): Observable[B]
Creates a new Observable that emits the events of the source and then it also emits the given element (appended to the stream).
Creates a new Observable that emits the events of the source and then it also emits the given element (appended to the stream).
- Definition Classes
- Observable
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
ambWith[B >: A](other: Observable[B]): Observable[B]
Given the source observable and another
Observable, emits all of the items from the first of these Observables to emit an item and cancel the other.Given the source observable and another
Observable, emits all of the items from the first of these Observables to emit an item and cancel the other.- Definition Classes
- Observable
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
final
def
asyncBoundary[B >: A](overflowStrategy: OverflowStrategy[B]): Observable[B]
Forces a buffered asynchronous boundary.
Forces a buffered asynchronous boundary.
Internally it wraps the observer implementation given to
onSubscribeinto a BufferedSubscriber.Normally Monix's implementation guarantees that events are not emitted concurrently, and that the publisher MUST NOT emit the next event without acknowledgement from the consumer that it may proceed, however for badly behaved publishers, this wrapper provides the guarantee that the downstream Observer given in
subscribewill not receive concurrent events.WARNING: if the buffer created by this operator is unbounded, it can blow up the process if the data source is pushing events faster than what the observer can consume, as it introduces an asynchronous boundary that eliminates the back-pressure requirements of the data source. Unbounded is the default overflowStrategy, see OverflowStrategy for options.
- overflowStrategy
- the overflow strategy used for buffering, which specifies what to do in case we're dealing with a slow consumer - should an unbounded buffer be used, should back-pressure be applied, should the pipeline drop newer or older events, should it drop the whole buffer? See OverflowStrategy for more details.
- Definition Classes
- Observable
-
final
def
behavior[B >: A](initialValue: B)(implicit s: Scheduler): ConnectableObservable[B]
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e.
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e. whose source is shared by all observers). The underlying subject used is a BehaviorSubject.
- Definition Classes
- Observable
-
final
def
bufferIntrospective(maxSize: Int): Observable[List[A]]
Buffers signals while busy, after which it emits the buffered events as a single bundle.
Buffers signals while busy, after which it emits the buffered events as a single bundle.
This operator starts applying back-pressure when the underlying buffer's size is exceeded.
- Definition Classes
- Observable
-
final
def
bufferSliding(count: Int, skip: Int): Observable[Seq[A]]
Returns an observable that emits buffers of items it collects from the source observable.
Returns an observable that emits buffers of items it collects from the source observable. The resulting observable emits buffers every
skipitems, each containingcountitems.If the source observable completes, then the current buffer gets signaled downstream. If the source triggers an error then the current buffer is being dropped and the error gets propagated immediately.
For
countandskipthere are 3 possibilities:- in case
skip == count, then there are no items dropped and no overlap, the call being equivalent tobuffer(count) - in case
skip < count, then overlap between buffers happens, with the number of elements being repeated beingcount - skip - in case
skip > count, thenskip - countelements start getting dropped between windows
- count
the maximum size of each buffer before it should be emitted
- skip
how many items emitted by the source observable should be skipped before starting a new buffer. Note that when skip and count are equal, this is the same operation as
buffer(count)
- Definition Classes
- Observable
- in case
-
final
def
bufferTimed(timespan: FiniteDuration): Observable[Seq[A]]
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time.
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time.
This version of
bufferemits a new bundle of items periodically, every timespan amount of time, containing all items emitted by the source Observable since the previous bundle emission.If the source observable completes, then the current buffer gets signaled downstream. If the source triggers an error then the current buffer is being dropped and the error gets propagated immediately.
- timespan
the interval of time at which it should emit the buffered bundle
- Definition Classes
- Observable
-
final
def
bufferTimedAndCounted(timespan: FiniteDuration, maxCount: Int): Observable[Seq[A]]
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time.
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time.
The resulting observable emits connected, non-overlapping buffers, each of a fixed duration specified by the
timespanargument or a maximum size specified by themaxCountargument (whichever is reached first).If the source observable completes, then the current buffer gets signaled downstream. If the source triggers an error then the current buffer is being dropped and the error gets propagated immediately.
- timespan
the interval of time at which it should emit the buffered bundle
- maxCount
is the maximum bundle size, after which the buffered bundle gets forcefully emitted
- Definition Classes
- Observable
-
final
def
bufferTimedWithPressure(period: FiniteDuration, maxSize: Int): Observable[Seq[A]]
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time.
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time. Back-pressure the source when the buffer is full.
The resulting observable emits connected, non-overlapping buffers, each of a fixed duration specified by the
periodargument.The bundles are emitted at a fixed rate. If the source is silent, then the resulting observable will start emitting empty sequences.
If the source observable completes, then the current buffer gets signaled downstream. If the source triggers an error then the current buffer is being dropped and the error gets propagated immediately.
A
maxSizeargument is specified as the capacity of the bundle. In case the source is too fast andmaxSizeis reached, then the source will be back-pressured.The difference with bufferTimedAndCounted is that bufferTimedWithPressure applies back-pressure from the time when the buffer is full until the buffer is emitted, whereas bufferTimedAndCounted will forcefully emit the buffer when it's full.
- period
the interval of time at which it should emit the buffered bundle
- maxSize
is the maximum buffer size, after which the source starts being back-pressured
- Definition Classes
- Observable
-
final
def
bufferTumbling(count: Int): Observable[Seq[A]]
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time.
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time. This version of
bufferis emitting items once the internal buffer has reached the given count.If the source observable completes, then the current buffer gets signaled downstream. If the source triggers an error then the current buffer is being dropped and the error gets propagated immediately.
- count
the maximum size of each buffer before it should be emitted
- Definition Classes
- Observable
-
final
def
bufferWithSelector[S](selector: Observable[S], maxSize: Int): Observable[Seq[A]]
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time, whenever the
selectorobservable signals an event.Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time, whenever the
selectorobservable signals an event.The resulting observable collects the elements of the source in a buffer and emits that buffer whenever the given
selectorobservable emits anonNextevent, when the buffer is emitted as a sequence downstream and then reset. Thus the resulting observable emits connected, non-overlapping bundles triggered by the givenselector.If
selectorterminates with anonComplete, then the resulting observable also terminates normally. Ifselectorterminates with anonError, then the resulting observable also terminates with an error.If the source observable completes, then the current buffer gets signaled downstream. If the source triggers an error then the current buffer is being dropped and the error gets propagated immediately.
A
maxSizeargument is specified as the capacity of the bundle. In case the source is too fast andmaxSizeis reached, then the source will be back-pressured.- selector
is the observable that triggers the signaling of the current buffer
- maxSize
is the maximum bundle size, after which the source starts being back-pressured
- Definition Classes
- Observable
-
final
def
bufferWithSelector[S](selector: Observable[S]): Observable[Seq[A]]
Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time, whenever the
selectorobservable signals an event.Periodically gather items emitted by an observable into bundles and emit these bundles rather than emitting the items one at a time, whenever the
selectorobservable signals an event.The resulting observable collects the elements of the source in a buffer and emits that buffer whenever the given
selectorobservable emits anonNextevent, when the buffer is emitted as a sequence downstream and then reset. Thus the resulting observable emits connected, non-overlapping bundles triggered by the givenselector.If
selectorterminates with anonComplete, then the resulting observable also terminates normally. Ifselectorterminates with anonError, then the resulting observable also terminates with an error.If the source observable completes, then the current buffer gets signaled downstream. If the source triggers an error then the current buffer is being dropped and the error gets propagated immediately.
- selector
is the observable that triggers the signaling of the current buffer
- Definition Classes
- Observable
-
final
def
cache(maxCapacity: Int): Observable[A]
Caches the emissions from the source Observable and replays them in order to any subsequent Subscribers.
Caches the emissions from the source Observable and replays them in order to any subsequent Subscribers. This operator has similar behavior to replay except that this auto-subscribes to the source Observable rather than returning a ConnectableObservable for which you must call connect to activate the subscription.
When you call cache, it does not yet subscribe to the source Observable and so does not yet begin caching items. This only happens when the first Subscriber calls the resulting Observable's
subscribemethod.- maxCapacity
is the maximum buffer size after which old events start being dropped (according to what happens when using ReplaySubject.createLimited)
- returns
an Observable that, when first subscribed to, caches all of its items and notifications for the benefit of subsequent subscribers
- Definition Classes
- Observable
-
final
def
cache: Observable[A]
Caches the emissions from the source Observable and replays them in order to any subsequent Subscribers.
Caches the emissions from the source Observable and replays them in order to any subsequent Subscribers. This operator has similar behavior to replay except that this auto-subscribes to the source Observable rather than returning a ConnectableObservable for which you must call connect to activate the subscription.
When you call cache, it does not yet subscribe to the source Observable and so does not yet begin caching items. This only happens when the first Subscriber calls the resulting Observable's
subscribemethod.Note: You sacrifice the ability to cancel the origin when you use the cache operator so be careful not to use this on Observables that emit an infinite or very large number of items that will use up memory.
- returns
an Observable that, when first subscribed to, caches all of its items and notifications for the benefit of subsequent subscribers
- Definition Classes
- Observable
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
collect[B](pf: PartialFunction[A, B]): Observable[B]
Applies the given partial function to the source for each element for which the given partial function is defined.
Applies the given partial function to the source for each element for which the given partial function is defined.
- pf
the function that filters and maps the source
- returns
an observable that emits the transformed items by the given partial function
- Definition Classes
- Observable
-
final
def
combineLatest[B](other: Observable[B]): Observable[(A, B)]
Creates a new observable from the source and another given observable, by emitting elements combined in pairs.
Creates a new observable from the source and another given observable, by emitting elements combined in pairs. If one of the observables emits fewer events than the other, then the rest of the unpaired events are ignored.
See zip for an alternative that pairs the items in strict sequence.
- other
is an observable that gets paired with the source
- Definition Classes
- Observable
-
final
def
combineLatestMap[B, R](other: Observable[B])(f: (A, B) ⇒ R): Observable[R]
Creates a new observable from the source and another given observable, by emitting elements combined in pairs.
Creates a new observable from the source and another given observable, by emitting elements combined in pairs. If one of the observables emits fewer events than the other, then the rest of the unpaired events are ignored.
See zipMap for an alternative that pairs the items in strict sequence.
- other
is an observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
completed: Observable[Nothing]
Ignores all items emitted by the source Observable and only calls onCompleted or onError.
Ignores all items emitted by the source Observable and only calls onCompleted or onError.
- returns
an empty Observable that only calls onCompleted or onError, based on which one is called by the source Observable
- Definition Classes
- Observable
-
final
def
completedL: Task[Unit]
Creates a new Task that will consume the source observable and upon completion of the source it will complete with
Unit.Creates a new Task that will consume the source observable and upon completion of the source it will complete with
Unit.- Definition Classes
- Observable
-
final
def
concat[B](implicit ev: <:<[A, Observable[B]]): Observable[B]
Concatenates the sequence of observables emitted by the source into one observable, without any transformation.
Concatenates the sequence of observables emitted by the source into one observable, without any transformation.
You can combine the items emitted by multiple observables so that they act like a single sequence by using this operator.
The difference between the
concatoperation andmergeis thatconcatcares about the ordering of sequences (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables,concatis safe to use in all contexts, whereasmergerequires buffering.- returns
an observable that emits items that are the result of flattening the items emitted by the observables emitted by the source
- Definition Classes
- Observable
-
final
def
concatDelayErrors[B](implicit ev: <:<[A, Observable[B]]): Observable[B]
Concatenates the sequence of observables emitted by the source into one observable, without any transformation.
Concatenates the sequence of observables emitted by the source into one observable, without any transformation.
You can combine the items emitted by multiple observables so that they act like a single sequence by using this operator.
The difference between the
concatoperation andmergeis thatconcatcares about the ordering of sequences (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables,concatis safe to use in all contexts, whereasmergerequires buffering.This version is reserving onError notifications until all of the observables complete and only then passing the issued errors(s) downstream. Note that the streamed error is a CompositeException, since multiple errors from multiple streams can happen.
- returns
an observable that emits items that are the result of flattening the items emitted by the observables emitted by the source
- Definition Classes
- Observable
-
final
def
concatMap[B](f: (A) ⇒ Observable[B]): Observable[B]
Applies a function that you supply to each item emitted by the source observable, where that function returns observables, and then concatenating those resulting sequences and emitting the results of this concatenation.
Applies a function that you supply to each item emitted by the source observable, where that function returns observables, and then concatenating those resulting sequences and emitting the results of this concatenation.
The difference between the
concatoperation andmergeis thatconcatcares about the ordering of sequences (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables,concatis safe to use in all contexts, whereasmergerequires buffering.- Definition Classes
- Observable
-
final
def
concatMapDelayErrors[B](f: (A) ⇒ Observable[B]): Observable[B]
Applies a function that you supply to each item emitted by the source observable, where that function returns sequences and then concatenating those resulting sequences and emitting the results of this concatenation.
Applies a function that you supply to each item emitted by the source observable, where that function returns sequences and then concatenating those resulting sequences and emitting the results of this concatenation.
This version is reserving onError notifications until all of the observables complete and only then passing the issued errors(s) downstream. Note that the streamed error is a CompositeException, since multiple errors from multiple streams can happen.
- f
a function that, when applied to an item emitted by the source, returns an observable
- returns
an observable that emits items that are the result of flattening the items emitted by the observables emitted by the source
- Definition Classes
- Observable
-
final
def
consumeWith[R](f: Consumer[A, R]): Task[R]
On execution, consumes the source observable with the given Consumer, effectively transforming the source observable into a Task.
On execution, consumes the source observable with the given Consumer, effectively transforming the source observable into a Task.
- Definition Classes
- Observable
-
final
def
countF: Observable[Long]
Creates a new Observable that emits the total number of
onNextevents that were emitted by the source.Creates a new Observable that emits the total number of
onNextevents that were emitted by the source.Note that this Observable emits only one item after the source is complete. And in case the source emits an error, then only that error will be emitted.
- Definition Classes
- Observable
-
final
def
countL: Task[Long]
Creates a task that emits the total number of
onNextevents that were emitted by the source.Creates a task that emits the total number of
onNextevents that were emitted by the source.- Definition Classes
- Observable
-
final
def
debounce(timeout: FiniteDuration): Observable[A]
Only emit an item from an observable if a particular timespan has passed without it emitting another item.
Only emit an item from an observable if a particular timespan has passed without it emitting another item.
Note: If the source observable keeps emitting items more frequently than the length of the time window, then no items will be emitted by the resulting observable.
- timeout
the length of the window of time that must pass after the emission of an item from the source observable in which that observable emits no items in order for the item to be emitted by the resulting observable
- Definition Classes
- Observable
- See also
echoOnce for a similar operator that also mirrors the source observable
-
final
def
debounceRepeated(period: FiniteDuration): Observable[A]
Emits the last item from the source Observable if a particular timespan has passed without it emitting another item, and keeps emitting that item at regular intervals until the source breaks the silence.
Emits the last item from the source Observable if a particular timespan has passed without it emitting another item, and keeps emitting that item at regular intervals until the source breaks the silence.
So compared to regular debounceTo this version keeps emitting the last item of the source.
Note: If the source Observable keeps emitting items more frequently than the length of the time window then no items will be emitted by the resulting Observable.
- period
the length of the window of time that must pass after the emission of an item from the source Observable in which that Observable emits no items in order for the item to be emitted by the resulting Observable at regular intervals, also determined by period
- Definition Classes
- Observable
- See also
echoRepeated for a similar operator that also mirrors the source observable
-
final
def
debounceTo[B](timeout: FiniteDuration, f: (A) ⇒ Observable[B]): Observable[B]
Doesn't emit anything until a
timeoutperiod passes without the source emitting anything.Doesn't emit anything until a
timeoutperiod passes without the source emitting anything. When that timeout happens, we subscribe to the observable generated by the given function, an observable that will keep emitting until the source will break the silence by emitting another event.Note: If the source observable keeps emitting items more frequently than the length of the time window, then no items will be emitted by the resulting Observable.
- timeout
the length of the window of time that must pass after the emission of an item from the source Observable in which that Observable emits no items in order for the item to be emitted by the resulting Observable
- f
is a function that receives the last element generated by the source, generating an observable to be subscribed when the source is timing out
- Definition Classes
- Observable
-
final
def
defaultIfEmpty[B >: A](default: ⇒ B): Observable[B]
Emit items from the source, or emit a default item if the source completes after emitting no items.
Emit items from the source, or emit a default item if the source completes after emitting no items.
- Definition Classes
- Observable
-
final
def
delayOnComplete(delay: FiniteDuration): Observable[A]
Delays emitting the final
onCompleteevent by the specified amount.Delays emitting the final
onCompleteevent by the specified amount.- Definition Classes
- Observable
-
final
def
delayOnNext(duration: FiniteDuration): Observable[A]
Returns an Observable that emits the items emitted by the source Observable shifted forward in time by a specified delay.
Returns an Observable that emits the items emitted by the source Observable shifted forward in time by a specified delay.
Each time the source Observable emits an item, delay starts a timer, and when that timer reaches the given duration, the Observable returned from delay emits the same item.
NOTE: this delay refers strictly to the time between the
onNextevent coming from our source and the time it takes the downstream observer to get this event. On the other hand the operator is also applying back-pressure, so on slow observers the actual time passing between two successive events may be higher than the specifiedduration.- duration
- the delay to shift the source by
- returns
the source Observable shifted in time by the specified delay
- Definition Classes
- Observable
-
final
def
delayOnNextBySelector[B](selector: (A) ⇒ Observable[B]): Observable[A]
Returns an Observable that emits the items emitted by the source Observable shifted forward in time.
Returns an Observable that emits the items emitted by the source Observable shifted forward in time.
This variant of
delaysets its delay duration on a per-item basis by passing each item from the source Observable into a function that returns an Observable and then monitoring those Observables. When any such Observable emits an item or completes, the Observable returned by delay emits the associated item.- selector
is a function that returns an Observable for each item emitted by the source Observable, which is then used to delay the emission of that item by the resulting Observable until the Observable returned from
selectoremits an item- returns
the source Observable shifted in time by the specified delay
- Definition Classes
- Observable
-
final
def
delaySubscription(timespan: FiniteDuration): Observable[A]
Hold an Observer's subscription request for a specified amount of time before passing it on to the source Observable.
Hold an Observer's subscription request for a specified amount of time before passing it on to the source Observable.
- timespan
is the time to wait before the subscription is being initiated.
- Definition Classes
- Observable
-
final
def
delaySubscriptionWith(trigger: Observable[Any]): Observable[A]
Hold an Observer's subscription request until the given
triggerobservable either emits an item or completes, before passing it on to the source Observable.Hold an Observer's subscription request until the given
triggerobservable either emits an item or completes, before passing it on to the source Observable.If the given
triggercompletes in error, then the subscription is terminated withonError.- trigger
the observable that must either emit an item or complete in order for the source to be subscribed.
- Definition Classes
- Observable
-
final
def
dematerialize[B](implicit ev: <:<[A, Notification[B]]): Observable[B]
Converts the source Observable that emits
Notification[A](the result of materialize) back to an Observable that emitsA.Converts the source Observable that emits
Notification[A](the result of materialize) back to an Observable that emitsA.- Definition Classes
- Observable
-
final
def
distinctUntilChanged[AA >: A](implicit A: Eq[AA]): Observable[AA]
Suppress duplicate consecutive items emitted by the source.
Suppress duplicate consecutive items emitted by the source.
Example:
// Yields 1, 2, 1, 3, 2, 4 Observable(1, 1, 1, 2, 2, 1, 1, 3, 3, 3, 2, 2, 4, 4, 4) .distinctUntilChanged
Duplication is detected by using the equality relationship provided by the
cats.Eqtype class. This allows one to override the equality operation being used (e.g. maybe the default.equalsis badly defined, or maybe you want reference equality, so depending on use case).In case type
Ais a primitive type and anEq[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anEq[A]instance defined for it, then you can quickly define one like this:import cats.Eq implicit val eqA = Eq.fromUniversalEquals[A]
- A
is the
cats.Eqinstance that defines equality for the elements emitted by the source
- Definition Classes
- Observable
-
final
def
distinctUntilChangedByKey[K](key: (A) ⇒ K)(implicit K: Eq[K]): Observable[A]
Given a function that returns a key for each element emitted by the source, suppress consecutive duplicate items.
Given a function that returns a key for each element emitted by the source, suppress consecutive duplicate items.
Example:
// Yields 1, 2, 3, 4 Observable(1, 3, 2, 4, 2, 3, 5, 7, 4) .distinctUntilChangedBy(_ % 2)
Duplication is detected by using the equality relationship provided by the
cats.Eqtype class. This allows one to override the equality operation being used (e.g. maybe the default.equalsis badly defined, or maybe you want reference equality, so depending on use case).In case type
Kis a primitive type and anEq[K]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Kdoes not have anEq[K]instance defined for it, then you can quickly define one like this:import cats.Eq implicit val eqK = Eq.fromUniversalEquals[K]
- key
is a function that returns a
Kkey for each element, a value that's then used to do the deduplication- K
is the
cats.Eqinstance that defines equality for the key typeK
- Definition Classes
- Observable
-
final
def
doAfterSubscribe(cb: () ⇒ Unit): Observable[A]
Executes the given callback just after the subscription happens.
Executes the given callback just after the subscription happens.
- Definition Classes
- Observable
- See also
doOnSubscribe for executing a callback just before a subscription happens.
-
final
def
doAfterTerminate(cb: (Option[Throwable]) ⇒ Unit): Observable[A]
Executes the given callback after the stream has ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.Executes the given callback after the stream has ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.This differs from doOnTerminate in that this happens *after* the
onCompleteoronErrornotification.- Definition Classes
- Observable
- See also
doAfterTerminateTask for a version that allows for asynchronous evaluation by means of Task.
-
final
def
doAfterTerminateEval[F[_]](cb: (Option[Throwable]) ⇒ F[Unit])(implicit F: Effect[F]): Observable[A]
Evaluates the effect generated by the given callback after the stream has ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.Evaluates the effect generated by the given callback after the stream has ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.This operation subsumes doOnEarlyStopEval and the callback-generated value will back-pressure the source when applied for
Stopevents returned byonNextand thus the upstream source will receive theStopresult only after the task has finished executing.The callback-generated
F[_]is a data type that should implementcats.effect.Effectand is thus capable of asynchronous evaluation (e.g.Task,IO, etc).This differs from doOnTerminateEval in that this happens *after* the
onCompleteoronErrornotification.- Definition Classes
- Observable
- See also
doAfterTerminate for a simpler version that doesn't allow asynchronous execution, or doAfterTerminateTask for a version that's specialized for Task.
-
final
def
doAfterTerminateTask(cb: (Option[Throwable]) ⇒ Task[Unit]): Observable[A]
Evaluates the task generated by the given callback after the stream has ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.Evaluates the task generated by the given callback after the stream has ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.This operation subsumes doOnEarlyStopTask and the callback-generated Task will back-pressure the source when applied for
Stopevents returned byonNextand thus the upstream source will receive theStopresult only after the task has finished executing.This differs from doOnTerminateTask in that this happens *after* the
onCompleteoronErrornotification.- Definition Classes
- Observable
- See also
doAfterTerminate for a simpler version that doesn't allow asynchronous execution.
-
final
def
doOnComplete(cb: () ⇒ Unit): Observable[A]
Executes the given callback when the stream has ended with an
onCompleteevent, but before the complete event is emitted.Executes the given callback when the stream has ended with an
onCompleteevent, but before the complete event is emitted.Unless you know what you're doing, you probably want to use doOnTerminate and doOnSubscriptionCancel for proper disposal of resources on completion.
- cb
the callback to execute when the
onCompleteevent gets emitted
- Definition Classes
- Observable
- See also
doOnCompleteTask for a version that allows for asynchronous evaluation by means of Task.
-
final
def
doOnCompleteEval[F[_]](effect: F[Unit])(implicit F: Effect[F]): Observable[A]
Evaluates the given
effectwhen the stream has ended with anonCompleteevent, but before the complete event is emitted.Evaluates the given
effectwhen the stream has ended with anonCompleteevent, but before the complete event is emitted.The
effectgets evaluated and is finished *before* theonCompletesignal gets sent downstream.This version of doOnComplete evaluates the given side effects using the specified
F[_]data type, which should implementcats.effect.Effect.Unless you know what you're doing, you probably want to use doOnTerminateTask and doOnSubscriptionCancel for proper disposal of resources on completion.
- effect
the action to execute when the
onCompleteevent gets emitted, its type being one that implementscats.effect.Effectand thus capable of delayed and asynchronous evaluation
- Definition Classes
- Observable
- See also
doOnComplete for a simpler version that doesn't do asynchronous execution, or doOnCompleteTask for a version specialized for Task
-
final
def
doOnCompleteTask(task: Task[Unit]): Observable[A]
Evaluates the given task when the stream has ended with an
onCompleteevent, but before the complete event is emitted.Evaluates the given task when the stream has ended with an
onCompleteevent, but before the complete event is emitted.The task gets evaluated and is finished *before* the
onCompletesignal gets sent downstream.Unless you know what you're doing, you probably want to use doOnTerminateTask and doOnSubscriptionCancel for proper disposal of resources on completion.
- task
the task to execute when the
onCompleteevent gets emitted
- Definition Classes
- Observable
- See also
doOnComplete for a simpler version that doesn't do asynchronous execution, or doOnCompleteEval for a version that can work with any data type implementing
cats.effect.Effect.
-
final
def
doOnEarlyStop(cb: () ⇒ Unit): Observable[A]
Executes the given callback when the streaming is stopped due to a downstream Stop signal returned by onNext.
Executes the given callback when the streaming is stopped due to a downstream Stop signal returned by onNext.
- Definition Classes
- Observable
- See also
doOnEarlyStopTask for a version that allows for asynchronous evaluation by means of Task, or doOnEarlyStopEval that allows using other data types for dealing with evaluation and side effects.
-
final
def
doOnEarlyStopEval[F[_]](effect: F[Unit])(implicit F: Effect[F]): Observable[A]
Executes the given task when the streaming is stopped due to a downstream Stop signal returned by onNext.
Executes the given task when the streaming is stopped due to a downstream Stop signal returned by onNext.
The given
effectgets evaluated *before* the upstream receives theStopevent (is back-pressured). This version of doOnEarlyStop is using anyF[_]data type that implementscats.effect.Effect(e.g.Task,IO, etc).- Definition Classes
- Observable
- See also
doOnEarlyStop for a simpler version, or doOnEarlyStopTask for a version that's specialized for Task.
-
final
def
doOnEarlyStopTask(task: Task[Unit]): Observable[A]
Executes the given task when the streaming is stopped due to a downstream Stop signal returned by onNext.
Executes the given task when the streaming is stopped due to a downstream Stop signal returned by onNext.
The given
taskgets evaluated *before* the upstream receives theStopevent (is back-pressured).- Definition Classes
- Observable
- See also
doOnEarlyStop for a simpler version, or doOnEarlyStopEval for a version that can use any data type that implements
cats.effect.Effect.
-
final
def
doOnError(cb: (Throwable) ⇒ Unit): Observable[A]
Executes the given callback when the stream is interrupted with an error, before the
onErrorevent is emitted downstream.Executes the given callback when the stream is interrupted with an error, before the
onErrorevent is emitted downstream.NOTE: should protect the code in this callback, because if it throws an exception the
onErrorevent will prefer signaling the original exception and otherwise the behavior is undefined.- Definition Classes
- Observable
- See also
doOnTerminate and doOnSubscriptionCancel for handling resource disposal, also see doOnErrorTask for a version that does asynchronous evaluation by means of Task.
-
final
def
doOnErrorEval[F[_]](cb: (Throwable) ⇒ F[Unit])(implicit F: Effect[F]): Observable[A]
Executes the given
cbwhen the stream is interrupted with an error, before theonErrorevent is emitted downstream.Executes the given
cbwhen the stream is interrupted with an error, before theonErrorevent is emitted downstream.This version of doOnError evaluates the given side effects using the specified
F[_]data type, which should implementcats.effect.Effect, thus being able of asynchronous execution.NOTE: should protect the code in this callback, because if it throws an exception the
onErrorevent will prefer signaling the original exception and otherwise the behavior is undefined.- Definition Classes
- Observable
- See also
doOnTerminateTask and doOnSubscriptionCancel for handling resource disposal, also see doOnError for a simpler version that doesn't do asynchronous execution, or doOnErrorTask for a version specialized on Task.
-
final
def
doOnErrorTask(cb: (Throwable) ⇒ Task[Unit]): Observable[A]
Executes the given task when the stream is interrupted with an error, before the
onErrorevent is emitted downstream.Executes the given task when the stream is interrupted with an error, before the
onErrorevent is emitted downstream.NOTE: should protect the code in this callback, because if it throws an exception the
onErrorevent will prefer signaling the original exception and otherwise the behavior is undefined.- Definition Classes
- Observable
- See also
doOnTerminateTask and doOnSubscriptionCancel for handling resource disposal, also see doOnError for a simpler version that doesn't do asynchronous execution, or doOnErrorEval for a version that can use any
Effectdata type.
-
final
def
doOnNext(cb: (A) ⇒ Unit): Observable[A]
Executes the given callback for each element generated by the source Observable, useful for doing side-effects.
Executes the given callback for each element generated by the source Observable, useful for doing side-effects.
- returns
a new Observable that executes the specified callback for each element
- Definition Classes
- Observable
- See also
doOnNextTask for a version that allows for asynchronous evaluation by means of Task.
-
final
def
doOnNextAck(cb: (A, Ack) ⇒ Unit): Observable[A]
Executes the given callback on each acknowledgement received from the downstream subscriber.
Executes the given callback on each acknowledgement received from the downstream subscriber.
This method helps in executing logic after messages get processed, for example when messages are polled from some distributed message queue and an acknowledgement needs to be sent after each message in order to mark it as processed.
- Definition Classes
- Observable
- See also
doOnNextAckTask for a version that allows for asynchronous evaluation by means of Task, or doOnNextEval for a version that can do evaluation with any data type implementing
cats.effect.Effect.
-
final
def
doOnNextAckEval[F[_]](cb: (A, Ack) ⇒ F[Unit])(implicit F: Effect[F]): Observable[A]
Executes the given callback on each acknowledgement received from the downstream subscriber, executing a generated effect and back-pressuring until it is done executing.
Executes the given callback on each acknowledgement received from the downstream subscriber, executing a generated effect and back-pressuring until it is done executing.
This method helps in executing logic after messages get processed, for example when messages are polled from some distributed message queue and an acknowledgement needs to be sent after each message in order to mark it as processed.
This version of doOnNext evaluates side effects with any data type that implements
cats.effect.Effect(e.g.Task,IO).- Definition Classes
- Observable
- See also
doOnNextAck for a simpler version that doesn't allow asynchronous execution, or doOnNextAckTask for a version that's specialized on Task.
-
final
def
doOnNextAckTask(cb: (A, Ack) ⇒ Task[Unit]): Observable[A]
Executes the given callback on each acknowledgement received from the downstream subscriber, executing a generated Task and back-pressuring until the task is done.
Executes the given callback on each acknowledgement received from the downstream subscriber, executing a generated Task and back-pressuring until the task is done.
This method helps in executing logic after messages get processed, for example when messages are polled from some distributed message queue and an acknowledgement needs to be sent after each message in order to mark it as processed.
- Definition Classes
- Observable
- See also
doOnNextAck for a simpler version that doesn't allow asynchronous execution, or doOnNextAckTask for a version that's specialized on Task.
-
final
def
doOnNextEval[F[_]](cb: (A) ⇒ F[Unit])(implicit F: Effect[F]): Observable[A]
Evaluates the given callback for each element generated by the source Observable, useful for triggering async side-effects.
Evaluates the given callback for each element generated by the source Observable, useful for triggering async side-effects.
This version of doOnNext evaluates side effects with any data type that implements
cats.effect.Effect(e.g.Task,IO).- returns
a new Observable that executes the specified callback for each element
- Definition Classes
- Observable
- See also
doOnNext for a simpler version that doesn't allow asynchronous execution, or doOnNextTask for a version that's specialized on Task.
-
final
def
doOnNextTask(cb: (A) ⇒ Task[Unit]): Observable[A]
Evaluates the given callback for each element generated by the source Observable, useful for triggering async side-effects.
Evaluates the given callback for each element generated by the source Observable, useful for triggering async side-effects.
- returns
a new Observable that executes the specified callback for each element
- Definition Classes
- Observable
- See also
doOnNext for a simpler version that doesn't allow asynchronous execution.
-
final
def
doOnStart(cb: (A) ⇒ Unit): Observable[A]
Executes the given callback only for the first element generated by the source Observable, useful for doing a piece of computation only when the stream starts.
Executes the given callback only for the first element generated by the source Observable, useful for doing a piece of computation only when the stream starts.
- returns
a new Observable that executes the specified callback only for the first element
- Definition Classes
- Observable
-
final
def
doOnSubscribe(cb: () ⇒ Unit): Observable[A]
Executes the given callback just before the subscription happens.
Executes the given callback just before the subscription happens.
- Definition Classes
- Observable
- See also
doAfterSubscribe for executing a callback just after a subscription happens.
-
final
def
doOnSubscriptionCancel(cb: () ⇒ Unit): Observable[A]
Executes the given callback when the connection is being cancelled.
Executes the given callback when the connection is being cancelled.
- Definition Classes
- Observable
-
final
def
doOnTerminate(cb: (Option[Throwable]) ⇒ Unit): Observable[A]
Executes the given callback right before the streaming is ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.Executes the given callback right before the streaming is ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.It is the equivalent of calling:
This differs from doAfterTerminate in that this happens *before* the
onCompleteoronErrornotification.- Definition Classes
- Observable
- See also
doOnTerminateTask for a version that allows for asynchronous evaluation by means of Task.
-
final
def
doOnTerminateEval[F[_]](cb: (Option[Throwable]) ⇒ F[Unit])(implicit F: Effect[F]): Observable[A]
Evaluates the callback right before the streaming is ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.Evaluates the callback right before the streaming is ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.The callback-generated
F[_]is a data type that should implementcats.effect.Effectand is thus capable of asynchronous evaluation, back-pressuring the source when applied forStopevents returned byonNextand thus the upstream source will receive theStopresult only after the task has finished executing.It is the equivalent of calling:
This differs from doAfterTerminateTask in that this happens *before* the
onCompleteoronErrornotification.- Definition Classes
- Observable
- See also
doOnTerminate for a simpler version that doesn't allow asynchronous execution, or doOnTerminateTask for a version that's specialized on Task.
-
final
def
doOnTerminateTask(cb: (Option[Throwable]) ⇒ Task[Unit]): Observable[A]
Evaluates the task generated by the given callback right before the streaming is ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.Evaluates the task generated by the given callback right before the streaming is ended either with an
onCompleteoronErrorevent, or when the streaming stops by a downstreamStopbeing signaled.The callback-generated Task will back-pressure the source when applied for
Stopevents returned byonNextand thus the upstream source will receive theStopresult only after the task has finished executing.It is the equivalent of calling:
This differs from doAfterTerminateTask in that this happens *before* the
onCompleteoronErrornotification.- Definition Classes
- Observable
- See also
doOnTerminate for a simpler version that doesn't allow asynchronous execution, or doOnTerminateEval for a version that can work with any
cats.effect.Effecttype.
-
final
def
drop(n: Int): Observable[A]
Drops the first
nelements (from the start).Drops the first
nelements (from the start).- n
the number of elements to drop
- returns
a new Observable that drops the first n elements emitted by the source
- Definition Classes
- Observable
-
final
def
dropByTimespan(timespan: FiniteDuration): Observable[A]
Creates a new observable that drops the events of the source, only for the specified
timestampwindow.Creates a new observable that drops the events of the source, only for the specified
timestampwindow.- timespan
the window of time during which the new observable must drop events emitted by the source
- Definition Classes
- Observable
-
final
def
dropLast(n: Int): Observable[A]
Drops the last
nelements (from the end).Drops the last
nelements (from the end).- n
the number of elements to drop
- returns
a new Observable that drops the first n elements emitted by the source
- Definition Classes
- Observable
-
final
def
dropUntil(trigger: Observable[Any]): Observable[A]
Discard items emitted by the source until a second observable emits an item or completes.
Discard items emitted by the source until a second observable emits an item or completes.
If the
triggerobservable completes in error, then the resulting observable will also end in error when it notices it (next time an element is emitted by the source).- trigger
the observable that has to emit an item before the source begin to be mirrored by the resulting observable
- Definition Classes
- Observable
-
final
def
dropWhile(p: (A) ⇒ Boolean): Observable[A]
Drops the longest prefix of elements that satisfy the given predicate and returns a new observable that emits the rest.
Drops the longest prefix of elements that satisfy the given predicate and returns a new observable that emits the rest.
- Definition Classes
- Observable
-
final
def
dropWhileWithIndex(p: (A, Int) ⇒ Boolean): Observable[A]
Drops the longest prefix of elements that satisfy the given function and returns a new observable that emits the rest.
Drops the longest prefix of elements that satisfy the given function and returns a new observable that emits the rest. In comparison with dropWhile, this version accepts a function that takes an additional parameter: the zero-based index of the element.
- Definition Classes
- Observable
-
final
def
dump(prefix: String, out: PrintStream = System.out): Observable[A]
Utility that can be used for debugging purposes.
Utility that can be used for debugging purposes.
- Definition Classes
- Observable
-
final
def
echoOnce(timeout: FiniteDuration): Observable[A]
Mirror the source observable as long as the source keeps emitting items, otherwise if
timeoutpasses without the source emitting anything new then the observable will emit the last item.Mirror the source observable as long as the source keeps emitting items, otherwise if
timeoutpasses without the source emitting anything new then the observable will emit the last item.This is the rough equivalent of:
Observable.merge(source, source.debounce(period))
Note: If the source Observable keeps emitting items more frequently than the length of the time window then the resulting observable will mirror the source exactly.
- timeout
the window of silence that must pass in order for the observable to echo the last item
- Definition Classes
- Observable
-
final
def
echoRepeated(timeout: FiniteDuration): Observable[A]
Mirror the source observable as long as the source keeps emitting items, otherwise if
timeoutpasses without the source emitting anything new then the observable will start emitting the last item repeatedly.Mirror the source observable as long as the source keeps emitting items, otherwise if
timeoutpasses without the source emitting anything new then the observable will start emitting the last item repeatedly.Note: If the source Observable keeps emitting items more frequently than the length of the time window then the resulting observable will mirror the source exactly.
- timeout
the window of silence that must pass in order for the observable to start echoing the last item
- Definition Classes
- Observable
-
final
def
endWith[B >: A](elems: Seq[B]): Observable[B]
Creates a new Observable that emits the events of the source and then it also emits the given elements (appended to the stream).
Creates a new Observable that emits the events of the source and then it also emits the given elements (appended to the stream).
- Definition Classes
- Observable
-
final
def
endWithError(error: Throwable): Observable[A]
Emits the given exception instead of
onComplete.Emits the given exception instead of
onComplete.- error
the exception to emit onComplete
- returns
a new Observable that emits an exception onComplete
- Definition Classes
- Observable
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
executeAsync: Observable[A]
Mirrors the source observable, but upon subscription ensure that the evaluation forks into a separate (logical) thread.
Mirrors the source observable, but upon subscription ensure that the evaluation forks into a separate (logical) thread.
The execution is managed by the injected scheduler in
subscribe().- Definition Classes
- Observable
-
final
def
executeOn(s: Scheduler, forceAsync: Boolean = true): Observable[A]
Overrides the default Scheduler, possibly forcing an asynchronous boundary on subscription (if
forceAsyncis set totrue, the default).Overrides the default Scheduler, possibly forcing an asynchronous boundary on subscription (if
forceAsyncis set totrue, the default).When an
Observableis subscribed with subscribe, it needs aScheduler, which is going to be injected in the processing pipeline, to be used for managing asynchronous boundaries, scheduling execution with delay, etc.Normally the Scheduler gets injected implicitly when doing
subscribe, but this operator overrides the injected subscriber for the given source. And if the source is normally using that injected scheduler (given bysubscribe), then the effect will be that all processing will now happen on the override.To put it in other words, in Monix it's usually the consumer and not the producer that specifies the scheduler and this operator allows for a different behavior.
This operator also subsumes the effects of subscribeOn, meaning that the subscription logic itself will start on the provided scheduler if
forceAsync = true(the default).- s
is the Scheduler to use for overriding the default scheduler and for forcing an asynchronous boundary if
forceAsyncistrue- forceAsync
indicates whether an asynchronous boundary should be forced right before the subscription of the source
Observable, managed by the providedScheduler- returns
a new
Observablethat mirrors the source on subscription, but that uses the provided scheduler for overriding the default and possibly force an extra asynchronous boundary on execution
- Definition Classes
- Observable
- See also
observeOn and subscribeOn.
-
final
def
executeWithModel(em: ExecutionModel): Observable[A]
Returns a new observable that will execute the source with a different ExecutionModel.
Returns a new observable that will execute the source with a different ExecutionModel.
This allows fine-tuning the options injected by the scheduler locally. Example:
observable.executeWithModel(AlwaysAsyncExecution)
- em
is the ExecutionModel that will be used when evaluating the source.
- Definition Classes
- Observable
-
final
def
existsF(p: (A) ⇒ Boolean): Observable[Boolean]
Returns an Observable which emits a single value, either true, in case the given predicate holds for at least one item, or false otherwise.
Returns an Observable which emits a single value, either true, in case the given predicate holds for at least one item, or false otherwise.
- p
is a function that evaluates the items emitted by the source Observable, returning
trueif they pass the filter- returns
an Observable that emits only true or false in case the given predicate holds or not for at least one item
- Definition Classes
- Observable
-
final
def
existsL(p: (A) ⇒ Boolean): Task[Boolean]
Returns a
Taskwhich emits eithertrue, in case the given predicate holds for at least one item, orfalseotherwise.Returns a
Taskwhich emits eithertrue, in case the given predicate holds for at least one item, orfalseotherwise.- p
is a function that evaluates the items emitted by the source, returning
trueif they pass the filter- returns
a task that emits
trueorfalsein case the given predicate holds or not for at least one item
- Definition Classes
- Observable
-
final
def
failed: Observable[Throwable]
Returns an observable that emits a single Throwable, in case an error was thrown by the source, otherwise it isn't going to emit anything.
Returns an observable that emits a single Throwable, in case an error was thrown by the source, otherwise it isn't going to emit anything.
- Definition Classes
- Observable
-
final
def
filter(p: (A) ⇒ Boolean): Observable[A]
Only emits those items for which the given predicate holds.
Only emits those items for which the given predicate holds.
- p
a function that evaluates the items emitted by the source returning
trueif they pass the filter- returns
a new observable that emits only those items in the source for which the filter evaluates as
true
- Definition Classes
- Observable
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
findF(p: (A) ⇒ Boolean): Observable[A]
Returns an Observable which only emits the first item for which the predicate holds.
Returns an Observable which only emits the first item for which the predicate holds.
- p
is a function that evaluates the items emitted by the source Observable, returning
trueif they pass the filter- returns
an Observable that emits only the first item in the original Observable for which the filter evaluates as
true
- Definition Classes
- Observable
-
final
def
findL(p: (A) ⇒ Boolean): Task[Option[A]]
Returns a task which emits the first item for which the predicate holds.
Returns a task which emits the first item for which the predicate holds.
- p
is a function that evaluates the items emitted by the source observable, returning
trueif they pass the filter- returns
a task that emits the first item in the source observable for which the filter evaluates as
true
- Definition Classes
- Observable
-
final
def
firstL: Task[A]
Creates a new Task that upon execution will signal the first generated element of the source observable.
Creates a new Task that upon execution will signal the first generated element of the source observable.
In case the stream was empty, then the
Taskgets completed in error with aNoSuchElementException.- Definition Classes
- Observable
-
final
def
firstOptionL: Task[Option[A]]
Creates a new Task that upon execution will signal the first generated element of the source observable.
Creates a new Task that upon execution will signal the first generated element of the source observable.
Returns an
Optionbecause the source can be empty.- Definition Classes
- Observable
-
final
def
firstOrElseF[B >: A](default: ⇒ B): Observable[B]
Emits the first element emitted by the source, or otherwise if the source is completed without emitting anything, then the
defaultis emitted.Emits the first element emitted by the source, or otherwise if the source is completed without emitting anything, then the
defaultis emitted.Alias for
headOrElse.- Definition Classes
- Observable
-
final
def
firstOrElseL[B >: A](default: ⇒ B): Task[B]
Creates a new Task that upon execution will signal the first generated element of the source observable.
Creates a new Task that upon execution will signal the first generated element of the source observable.
In case the stream was empty, then the given default gets evaluated and emitted.
- Definition Classes
- Observable
-
final
def
flatMap[B](f: (A) ⇒ Observable[B]): Observable[B]
Applies a function that you supply to each item emitted by the source observable, where that function returns sequences that can be observed, and then concatenating those resulting sequences and emitting the results of this concatenation.
Applies a function that you supply to each item emitted by the source observable, where that function returns sequences that can be observed, and then concatenating those resulting sequences and emitting the results of this concatenation.
Alias for concatMap.
The difference between the
concatoperation andmergeis thatconcatcares about the ordering of sequences (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables,concatis safe to use in all contexts, whereasmergerequires buffering.- Definition Classes
- Observable
-
final
def
flatMapDelayErrors[B](f: (A) ⇒ Observable[B]): Observable[B]
Applies a function that you supply to each item emitted by the source observable, where that function returns sequences and then concatenating those resulting sequences and emitting the results of this concatenation.
Applies a function that you supply to each item emitted by the source observable, where that function returns sequences and then concatenating those resulting sequences and emitting the results of this concatenation.
It's an alias for concatMapDelayErrors.
- f
a function that, when applied to an item emitted by the source Observable, returns an Observable
- returns
an Observable that emits the result of applying the transformation function to each item emitted by the source Observable and concatenating the results of the Observables obtained from this transformation.
- Definition Classes
- Observable
-
final
def
flatMapLatest[B](f: (A) ⇒ Observable[B]): Observable[B]
An alias of switchMap.
An alias of switchMap.
Returns a new observable that emits the items emitted by the observable most recently generated by the mapping function.
- Definition Classes
- Observable
-
final
def
flatScan[R](seed: ⇒ R)(op: (R, A) ⇒ Observable[R]): Observable[R]
Applies a binary operator to a start value and to elements produced by the source observable, going from left to right, producing and concatenating observables along the way.
Applies a binary operator to a start value and to elements produced by the source observable, going from left to right, producing and concatenating observables along the way.
- Definition Classes
- Observable
-
final
def
flatScanDelayErrors[R](seed: ⇒ R)(op: (R, A) ⇒ Observable[R]): Observable[R]
Applies a binary operator to a start value and to elements produced by the source observable, going from left to right, producing and concatenating observables along the way.
Applies a binary operator to a start value and to elements produced by the source observable, going from left to right, producing and concatenating observables along the way.
This version of flatScan delays all errors until
onComplete, when it will finally emit a CompositeException. It's the combination between scan and flatMapDelayErrors.- Definition Classes
- Observable
-
final
def
flatten[B](implicit ev: <:<[A, Observable[B]]): Observable[B]
Concatenates the sequence of observables emitted by the source into one observable, without any transformation.
Concatenates the sequence of observables emitted by the source into one observable, without any transformation.
You can combine the items emitted by multiple observables so that they act like a single sequence by using this operator.
The difference between the
concatoperation andmergeis thatconcatcares about the ordering of sequences (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables,concatis safe to use in all contexts, whereasmergerequires buffering.Alias for concat.
- returns
an observable that emits items that are the result of flattening the items emitted by the observables emitted by the source
- Definition Classes
- Observable
-
final
def
flattenDelayErrors[B](implicit ev: <:<[A, Observable[B]]): Observable[B]
Alias for concatDelayErrors.
Alias for concatDelayErrors.
Concatenates the sequence of observables emitted by the source into one observable, without any transformation.
You can combine the items emitted by multiple observables so that they act like a single sequence by using this operator.
The difference between the
concatoperation andmergeis thatconcatcares about the ordering of sequences (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables,concatis safe to use in all contexts, whereasmergerequires buffering.This version is reserving onError notifications until all of the observables complete and only then passing the issued errors(s) downstream. Note that the streamed error is a CompositeException, since multiple errors from multiple streams can happen.
- returns
an observable that emits items that are the result of flattening the items emitted by the observables emitted by the source
- Definition Classes
- Observable
-
final
def
flattenLatest[B](implicit ev: <:<[A, Observable[B]]): Observable[B]
Alias for switch
Alias for switch
Convert an observable that emits observables into a single observable that emits the items emitted by the most-recently-emitted of those observables.
- Definition Classes
- Observable
-
final
def
foldF[AA >: A](implicit A: Monoid[AA]): Observable[AA]
Given evidence that type
Ahas acats.Monoidimplementation, folds the stream with the provided monoid definition.Given evidence that type
Ahas acats.Monoidimplementation, folds the stream with the provided monoid definition.For streams emitting numbers, this effectively sums them up. For strings, this concatenates them.
Example:
// Yields 10 Observable(1, 2, 3, 4).foldF // Yields "1234" Observable("1", "2", "3", "4").foldF
Note, in case you don't have a
Monoidinstance in scope, but you feel like you should, try this import:import cats.instances.all._- A
is the
cats.Monoidtype class instance that's needed in scope for folding the source- returns
the result of combining all elements of the source, or the defined
Monoid.emptyelement in case the stream is empty
- Definition Classes
- Observable
- See also
foldL for the version that returns a task instead of an observable.
-
final
def
foldL[AA >: A](implicit A: Monoid[AA]): Task[AA]
Given evidence that type
Ahas acats.Monoidimplementation, folds the stream with the provided monoid definition.Given evidence that type
Ahas acats.Monoidimplementation, folds the stream with the provided monoid definition.For streams emitting numbers, this effectively sums them up. For strings, this concatenates them.
Example:
// Yields 10 Observable(1, 2, 3, 4).foldL // Yields "1234" Observable("1", "2", "3", "4").foldL
Note, in case you don't have a
Monoidinstance in scope, but you feel like you should, try this import:import cats.instances.all._- A
is the
cats.Monoidtype class instance that's needed in scope for folding the source- returns
the result of combining all elements of the source, or the defined
Monoid.emptyelement in case the stream is empty
- Definition Classes
- Observable
- See also
foldF for the version that returns an observable instead of a task.
-
final
def
foldLeftF[R](seed: ⇒ R)(op: (R, A) ⇒ R): Observable[R]
Applies a binary operator to a start value and all elements of this Observable, going left to right and returns a new Observable that emits only one item before
onComplete.Applies a binary operator to a start value and all elements of this Observable, going left to right and returns a new Observable that emits only one item before
onComplete.- seed
is the initial state, specified as a possibly lazy value; it gets evaluated when the subscription happens and if it triggers an error then the subscriber will get immediately terminated with an error
- op
is an operator that will fold the signals of the source observable, returning the next state
- Definition Classes
- Observable
-
final
def
foldLeftL[R](seed: ⇒ R)(op: (R, A) ⇒ R): Task[R]
Applies a binary operator to a start value and all elements of the source, going left to right and returns a new
Taskthat upon evaluation will eventually emit the final result.Applies a binary operator to a start value and all elements of the source, going left to right and returns a new
Taskthat upon evaluation will eventually emit the final result.- Definition Classes
- Observable
-
final
def
foldWhileLeftF[S](seed: ⇒ S)(op: (S, A) ⇒ Either[S, S]): Observable[S]
Folds the source observable, from start to finish, until the source completes, or until the operator short-circuits the process by returning
false.Folds the source observable, from start to finish, until the source completes, or until the operator short-circuits the process by returning
false.Note that a call to foldLeftF is equivalent to this function being called with an operator always returning
trueas the first member of its result.Example:
// Sums first 10 items Observable.range(0, 1000).foldWhileLeftF((0, 0)) { case ((sum, count), e) => val next = (sum + e, count + 1) if (count + 1 < 10) Left(next) else Right(next) } // Implements exists(predicate) Observable(1, 2, 3, 4, 5).foldWhileLeftF(false) { (default, e) => if (e == 3) Right(true) else Left(default) } // Implements forall(predicate) Observable(1, 2, 3, 4, 5).foldWhileLeftF(true) { (default, e) => if (e != 3) Right(false) else Left(default) }
- seed
is the initial state, specified as a possibly lazy value; it gets evaluated when the subscription happens and if it triggers an error then the subscriber will get immediately terminated with an error
- op
is the binary operator returning either
Left, signaling that the state should be evolved or aRight, signaling that the process can be short-circuited and the result returned immediately- returns
the result of inserting
opbetween consecutive elements of this observable, going from left to right with theseedas the start value, orseedif the observable is empty
- Definition Classes
- Observable
- See also
foldWhileLeftL for a version that returns a task instead of an observable.
-
final
def
foldWhileLeftL[S](seed: ⇒ S)(op: (S, A) ⇒ Either[S, S]): Task[S]
Folds the source observable, from start to finish, until the source completes, or until the operator short-circuits the process by returning
false.Folds the source observable, from start to finish, until the source completes, or until the operator short-circuits the process by returning
false.Note that a call to foldLeftL is equivalent to this function being called with an operator always returning
Leftresults.Example:
// Sums first 10 items Observable.range(0, 1000).foldWhileLeftL((0, 0)) { case ((sum, count), e) => val next = (sum + e, count + 1) if (count + 1 < 10) Left(next) else Right(next) } // Implements exists(predicate) Observable(1, 2, 3, 4, 5).foldWhileLeftL(false) { (default, e) => if (e == 3) Right(true) else Left(default) } // Implements forall(predicate) Observable(1, 2, 3, 4, 5).foldWhileLeftL(true) { (default, e) => if (e != 3) Right(false) else Left(default) }
- seed
is the initial state, specified as a possibly lazy value; it gets evaluated when the subscription happens and if it triggers an error then the subscriber will get immediately terminated with an error
- op
is the binary operator returning either
Left, signaling that the state should be evolved or aRight, signaling that the process can be short-circuited and the result returned immediately- returns
the result of inserting
opbetween consecutive elements of this observable, going from left to right with theseedas the start value, orseedif the observable is empty
- Definition Classes
- Observable
- See also
foldWhileLeftF for a version that returns an observable instead of a task.
-
final
def
forAllF(p: (A) ⇒ Boolean): Observable[Boolean]
Returns an Observable that emits a single boolean, either true, in case the given predicate holds for all the items emitted by the source, or false in case at least one item is not verifying the given predicate.
Returns an Observable that emits a single boolean, either true, in case the given predicate holds for all the items emitted by the source, or false in case at least one item is not verifying the given predicate.
- p
is a function that evaluates the items emitted by the source Observable, returning
trueif they pass the filter- returns
an Observable that emits only true or false in case the given predicate holds or not for all the items
- Definition Classes
- Observable
-
final
def
forAllL(p: (A) ⇒ Boolean): Task[Boolean]
Returns a
Taskthat emits a single boolean, either true, in case the given predicate holds for all the items emitted by the source, or false in case at least one item is not verifying the given predicate.Returns a
Taskthat emits a single boolean, either true, in case the given predicate holds for all the items emitted by the source, or false in case at least one item is not verifying the given predicate.- p
is a function that evaluates the items emitted by the source observable, returning
trueif they pass the filter- returns
a task that emits only true or false in case the given predicate holds or not for all the items
- Definition Classes
- Observable
-
final
def
foreach(cb: (A) ⇒ Unit)(implicit s: Scheduler): CancelableFuture[Unit]
Subscribes to the source
Observableand foreach element emitted by the source it executes the given callback.Subscribes to the source
Observableand foreach element emitted by the source it executes the given callback.- Definition Classes
- Observable
-
final
def
foreachL(cb: (A) ⇒ Unit): Task[Unit]
Creates a new Task that will consume the source observable, executing the given callback for each element.
Creates a new Task that will consume the source observable, executing the given callback for each element.
- Definition Classes
- Observable
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
groupBy[K](keySelector: (A) ⇒ K)(implicit keysBuffer: Synchronous[Nothing] = OverflowStrategy.Unbounded): Observable[GroupedObservable[K, A]]
Groups the items emitted by an Observable according to a specified criterion, and emits these grouped items as GroupedObservables, one GroupedObservable per group.
Groups the items emitted by an Observable according to a specified criterion, and emits these grouped items as GroupedObservables, one GroupedObservable per group.
Note: A GroupedObservable will cache the items it is to emit until such time as it is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore those GroupedObservables that do not concern you. Instead, you can signal to them that they may discard their buffers by doing something like
source.take(0).- keySelector
a function that extracts the key for each item
- Definition Classes
- Observable
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
headF: Observable[A]
Only emits the first element emitted by the source observable, after which it's completed immediately.
Only emits the first element emitted by the source observable, after which it's completed immediately.
- Definition Classes
- Observable
-
final
def
headL: Task[A]
Alias for firstL.
Alias for firstL.
- Definition Classes
- Observable
-
final
def
headOptionL: Task[Option[A]]
Alias for firstOptionL.
Alias for firstOptionL.
- Definition Classes
- Observable
-
final
def
headOrElseF[B >: A](default: ⇒ B): Observable[B]
Emits the first element emitted by the source, or otherwise if the source is completed without emitting anything, then the
defaultis emitted.Emits the first element emitted by the source, or otherwise if the source is completed without emitting anything, then the
defaultis emitted.- Definition Classes
- Observable
-
final
def
headOrElseL[B >: A](default: ⇒ B): Task[B]
Alias for firstOrElseL.
Alias for firstOrElseL.
- Definition Classes
- Observable
-
final
def
ignoreElements: Observable[Nothing]
Alias for completed.
Alias for completed. Ignores all items emitted by the source and only calls onCompleted or onError.
- returns
an empty sequence that only calls onCompleted or onError, based on which one is called by the source Observable
- Definition Classes
- Observable
-
final
def
interleave[B >: A](other: Observable[B]): Observable[B]
Creates a new observable from this observable and another given observable by interleaving their items into a strictly alternating sequence.
Creates a new observable from this observable and another given observable by interleaving their items into a strictly alternating sequence.
So the first item emitted by the new observable will be the item emitted by
self, the second item will be emitted by the other observable, and so forth; when eitherselforothercallsonCompletes, the items will then be directly coming from the observable that has not completed; whenonErroris called by eitherselforother, the new observable will callonErrorand halt.See merge for a more relaxed alternative that doesn't emit items in strict alternating sequence.
- other
is an observable that interleaves with the source
- returns
a new observable sequence that alternates emission of the items from both child streams
- Definition Classes
- Observable
-
final
def
intersperse[B >: A](start: B, separator: B, end: B): Observable[B]
Creates a new observable from this observable that will emit the
startelement followed by the upstream elements paired with theseparator, and lastly theendelement.Creates a new observable from this observable that will emit the
startelement followed by the upstream elements paired with theseparator, and lastly theendelement.- start
is the first element emitted
- separator
is the separator
- end
the last element emitted
- Definition Classes
- Observable
-
final
def
intersperse[B >: A](separator: B): Observable[B]
Creates a new observable from this observable that will emit a specific
separatorbetween every pair of elements.Creates a new observable from this observable that will emit a specific
separatorbetween every pair of elements.- separator
is the separator
- Definition Classes
- Observable
-
final
def
isEmptyF: Observable[Boolean]
Returns an Observable that emits true if the source Observable is empty, otherwise false.
Returns an Observable that emits true if the source Observable is empty, otherwise false.
- Definition Classes
- Observable
-
final
def
isEmptyL: Task[Boolean]
Returns a task that emits
trueif the source observable is empty, otherwisefalse.Returns a task that emits
trueif the source observable is empty, otherwisefalse.- Definition Classes
- Observable
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
lastF: Observable[A]
Only emits the last element emitted by the source observable, after which it's completed immediately.
Only emits the last element emitted by the source observable, after which it's completed immediately.
- Definition Classes
- Observable
-
final
def
lastL: Task[A]
Returns a Task that upon execution will signal the last generated element of the source observable.
Returns a Task that upon execution will signal the last generated element of the source observable.
In case the stream was empty, then the
Taskgets completed in error with aNoSuchElementException.- Definition Classes
- Observable
-
final
def
lastOptionL: Task[Option[A]]
Returns a Task that upon execution will signal the last generated element of the source observable.
Returns a Task that upon execution will signal the last generated element of the source observable.
Returns an
Optionbecause the source can be empty.- Definition Classes
- Observable
-
final
def
lastOrElseL[B >: A](default: ⇒ B): Task[B]
Creates a new Task that upon execution will signal the last generated element of the source observable.
Creates a new Task that upon execution will signal the last generated element of the source observable.
In case the stream was empty, then the given default gets evaluated and emitted.
- Definition Classes
- Observable
-
final
def
liftByOperator[B](operator: Operator[A, B]): Observable[B]
Transforms the source using the given operator.
Transforms the source using the given operator.
- Definition Classes
- Observable
-
final
def
map[B](f: (A) ⇒ B): Observable[B]
Returns a new observable that applies the given function to each item emitted by the source and emits the result.
Returns a new observable that applies the given function to each item emitted by the source and emits the result.
- Definition Classes
- Observable
-
final
def
mapEval[F[_], B](f: (A) ⇒ F[B])(implicit F: Effect[F]): Observable[B]
Maps elements from the source using a function that can do lazy or asynchronous processing by means of any
F[_]data type that implementscats.effect.Effect(e.g.Maps elements from the source using a function that can do lazy or asynchronous processing by means of any
F[_]data type that implementscats.effect.Effect(e.g.Task,IO).Given a source observable, this function is basically the equivalent of doing:
observable.mapTask(a => Task.fromEffect(f(a)))- Definition Classes
- Observable
- See also
mapTask for a version specialized for Task and mapFuture for the version that can work with
scala.concurrent.Future
-
final
def
mapFuture[B](f: (A) ⇒ Future[B]): Observable[B]
Maps elements from the source using a function that can do asynchronous processing by means of
scala.concurrent.Future.Maps elements from the source using a function that can do asynchronous processing by means of
scala.concurrent.Future.Given a source observable, this function is basically the equivalent of doing:
observable.concatMap(a => Observable.fromFuture(f(a)))However prefer this operator to
concatMapbecause it is more clear and has better performance.- Definition Classes
- Observable
- See also
mapTask for the version that can work with Task
-
final
def
mapParallelUnordered[B](parallelism: Int)(f: (A) ⇒ Task[B])(implicit os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B]
Given a mapping function that maps events to tasks, applies it in parallel on the source, but with a specified
parallelism, which indicates the maximum number of tasks that can be executed in parallel.Given a mapping function that maps events to tasks, applies it in parallel on the source, but with a specified
parallelism, which indicates the maximum number of tasks that can be executed in parallel.Similar in spirit with Consumer.loadBalance, but expressed as an operator that executes Task instances in parallel.
Note that when the specified
parallelismis 1, it has the same behavior as mapTask.- parallelism
is the maximum number of tasks that can be executed in parallel, over which the source starts being back-pressured
- f
is the mapping function that produces tasks to execute in parallel, which will eventually produce events for the resulting observable stream
- Definition Classes
- Observable
- See also
mapTask for serial execution
-
final
def
mapTask[B](f: (A) ⇒ Task[B]): Observable[B]
Maps elements from the source using a function that can do asynchronous processing by means of Task.
Maps elements from the source using a function that can do asynchronous processing by means of Task.
Given a source observable, this function is basically the equivalent of doing:
observable.concatMap(a => Observable.fromTask(f(a)))However prefer this operator to
concatMapbecause it is more clear and has better performance.- Definition Classes
- Observable
- See also
mapFuture for the version that can work with
scala.concurrent.Future
-
final
def
materialize: Observable[Notification[A]]
Converts the source Observable that emits
Ainto an Observable that emitsNotification[A].Converts the source Observable that emits
Ainto an Observable that emitsNotification[A].- Definition Classes
- Observable
-
final
def
maxByF[K](key: (A) ⇒ K)(implicit K: Order[K]): Observable[A]
Takes the elements of the source observable and emits the element that has the maximum key value, where the key is generated by the given function.
Takes the elements of the source observable and emits the element that has the maximum key value, where the key is generated by the given function.
Example:
case class Person(name: String, age: Int) // Yields Observable(Person("Alex", 34)) Observable(Person("Alex", 34), Person("Alice", 27)) .maxByF(_.age)
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- key
is the function that returns the key for which the given ordering is defined
- K
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the maximum element of the source stream, relative to its key generated by the given function and the given ordering
- Definition Classes
- Observable
- See also
maxByL for the version that returns a Task instead of an observable.
-
final
def
maxByL[K](key: (A) ⇒ K)(implicit K: Order[K]): Task[Option[A]]
Takes the elements of the source observable and emits the element that has the maximum key value, where the key is generated by the given function.
Takes the elements of the source observable and emits the element that has the maximum key value, where the key is generated by the given function.
Example:
case class Person(name: String, age: Int) // Yields Some(Person("Alex", 34)) Observable(Person("Alex", 34), Person("Alice", 27)) .maxByL(_.age)
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- key
is the function that returns the key for which the given ordering is defined
- K
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the maximum element of the source stream, relative to its key generated by the given function and the given ordering
- Definition Classes
- Observable
- See also
maxByF for the version that returns an observable instead of a
Task.
-
final
def
maxF[AA >: A](implicit A: Order[AA]): Observable[AA]
Given a
cats.Orderover the stream's elements, returns the maximum element in the stream.Given a
cats.Orderover the stream's elements, returns the maximum element in the stream.Example:
// Yields Observable(20) Observable(10, 7, 6, 8, 20, 3, 5).maxF // Yields Observable.empty Observable.empty.maxF
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- A
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the maximum element of the source stream, relative to the defined
Order
- Definition Classes
- Observable
- See also
maxL for the version that returns a Task instead of an observable.
-
final
def
maxL[AA >: A](implicit A: Order[AA]): Task[Option[AA]]
Given a
cats.Orderover the stream's elements, returns the maximum element in the stream.Given a
cats.Orderover the stream's elements, returns the maximum element in the stream.Example:
// Yields Some(20) Observable(10, 7, 6, 8, 20, 3, 5).maxL // Yields Observable.empty Observable.empty.maxL
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- A
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the maximum element of the source stream, relative to the defined
Order
- Definition Classes
- Observable
- See also
maxF for the version that returns an observable instead of a
Task.
-
final
def
merge[B](implicit ev: <:<[A, Observable[B]], os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B]
Merges the sequence of Observables emitted by the source into one Observable, without any transformation.
Merges the sequence of Observables emitted by the source into one Observable, without any transformation.
You can combine the items emitted by multiple Observables so that they act like a single Observable by using this operator.
- returns
an Observable that emits items that are the result of flattening the items emitted by the Observables emitted by
this.
- Definition Classes
- Observable
- Note
this operation needs to do buffering and by not specifying an OverflowStrategy, the default strategy is being used.
-
final
def
mergeDelayErrors[B](implicit ev: <:<[A, Observable[B]], os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B]
Merges the sequence of Observables emitted by the source into one Observable, without any transformation.
Merges the sequence of Observables emitted by the source into one Observable, without any transformation.
You can combine the items emitted by multiple Observables so that they act like a single Observable by using this operator.
This version is reserving onError notifications until all of the observables complete and only then passing the issued errors(s) downstream. Note that the streamed error is a CompositeException, since multiple errors from multiple streams can happen.
- returns
an Observable that emits items that are the result of flattening the items emitted by the Observables emitted by
this.
- Definition Classes
- Observable
- Note
this operation needs to do buffering and by not specifying an OverflowStrategy, the default strategy is being used.
-
final
def
mergeMap[B](f: (A) ⇒ Observable[B])(implicit os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B]
Creates a new observable by applying a function that you supply to each item emitted by the source observable, where that function returns an observable, and then merging those resulting observable and emitting the results of this merger.
Creates a new observable by applying a function that you supply to each item emitted by the source observable, where that function returns an observable, and then merging those resulting observable and emitting the results of this merger.
The difference between this and
concatMapis thatconcatMapcares about ordering of emitted items (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables, theconcatoperation is safe to use in all contexts, whereasmergerequires buffering.- f
- the transformation function
- returns
an observable that emits the result of applying the transformation function to each item emitted by the source observable and merging the results of the observables obtained from this transformation.
- Definition Classes
- Observable
-
final
def
mergeMapDelayErrors[B](f: (A) ⇒ Observable[B])(implicit os: OverflowStrategy[B] = OverflowStrategy.Default): Observable[B]
Creates a new observable by applying a function that you supply to each item emitted by the source observable, where that function returns an observable, and then merging those resulting observable and emitting the results of this merger.
Creates a new observable by applying a function that you supply to each item emitted by the source observable, where that function returns an observable, and then merging those resulting observable and emitting the results of this merger.
The difference between this and
concatMapis thatconcatMapcares about ordering of emitted items (e.g. all items emitted by the first observable in the sequence will come before the elements emitted by the second observable), whereasmergedoesn't care about that (elements get emitted as they come). Because of back-pressure applied to observables, theconcatoperation is safe to use in all contexts, whereasmergerequires buffering.This version is reserving onError notifications until all of the observables complete and only then passing the issued errors(s) downstream. Note that the streamed error is a CompositeException, since multiple errors from multiple streams can happen.
- f
- the transformation function
- returns
an observable that emits the result of applying the transformation function to each item emitted by the source observable and merging the results of the observables obtained from this transformation.
- Definition Classes
- Observable
-
final
def
minByF[K](key: (A) ⇒ K)(implicit K: Order[K]): Observable[A]
Takes the elements of the source observable and emits the element that has the minimum key value, where the key is generated by the given function.
Takes the elements of the source observable and emits the element that has the minimum key value, where the key is generated by the given function.
Example:
case class Person(name: String, age: Int) // Yields Observable(Person("Alice", 27)) Observable(Person("Alex", 34), Person("Alice", 27)) .minByF(_.age)
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- key
is the function that returns the key for which the given ordering is defined
- K
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the minimum element of the source stream, relative to its key generated by the given function and the given ordering
- Definition Classes
- Observable
-
final
def
minByL[K](key: (A) ⇒ K)(implicit K: Order[K]): Task[Option[A]]
Takes the elements of the source observable and emits the element that has the minimum key value, where the key is generated by the given function.
Takes the elements of the source observable and emits the element that has the minimum key value, where the key is generated by the given function.
Example:
case class Person(name: String, age: Int) // Yields Some(Person("Alice", 27)) Observable(Person("Alex", 34), Person("Alice", 27)) .minByL(_.age)
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- key
is the function that returns the key for which the given ordering is defined
- K
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the minimum element of the source stream, relative to its key generated by the given function and the given ordering
- Definition Classes
- Observable
-
final
def
minF[AA >: A](implicit A: Order[AA]): Observable[AA]
Given a
cats.Orderover the stream's elements, returns the minimum element in the stream.Given a
cats.Orderover the stream's elements, returns the minimum element in the stream.Example:
// Yields Observable(3) Observable(10, 7, 6, 8, 20, 3, 5).minF // Yields Observable.empty Observable.empty.minF
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- A
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the minimum element of the source stream, relative to the defined
Order
- Definition Classes
- Observable
- See also
minL for the version that returns a Task instead of an observable.
-
final
def
minL[AA >: A](implicit A: Order[AA]): Task[Option[AA]]
Given a
cats.Orderover the stream's elements, returns the minimum element in the stream.Given a
cats.Orderover the stream's elements, returns the minimum element in the stream.Example:
// Yields Some(3) Observable(10, 7, 6, 8, 20, 3, 5).minL // Yields None Observable.empty.minL
In case type
Ais a primitive type and anOrder[A]instance is not in scope, then you probably need this import:import cats.instances.all._Or in case your type
Adoes not have anOrder[A]instance defined for it, but it does have a ScalaOrderingdefined, then you can define one like this:import cats.Order implicit val orderA = Order.fromOrdering[A]
- A
is the
cats.Ordertype class instance that's going to be used for comparing elements- returns
the minimum element of the source stream, relative to the defined
Order
- Definition Classes
- Observable
- See also
minF for the version that returns an observable instead of a
Task.
-
final
def
multicast[B >: A, R](pipe: Pipe[B, R])(implicit s: Scheduler): ConnectableObservable[R]
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e.
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e. whose source is shared by all observers).
- Definition Classes
- Observable
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
nonEmptyF: Observable[Boolean]
Returns an Observable that emits false if the source Observable is empty, otherwise true.
Returns an Observable that emits false if the source Observable is empty, otherwise true.
- Definition Classes
- Observable
-
final
def
nonEmptyL: Task[Boolean]
Returns a task that emits
falseif the source observable is empty, otherwisetrue.Returns a task that emits
falseif the source observable is empty, otherwisetrue.- Definition Classes
- Observable
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
observeOn[B >: A](s: Scheduler, os: OverflowStrategy[B]): Observable[B]
Operator that specifies a different Scheduler, on which subscribers will observe events, instead of the default one.
Operator that specifies a different Scheduler, on which subscribers will observe events, instead of the default one.
This overloaded version of
observeOntakes an extra OverflowStrategy parameter specifying the behavior of the underlying buffer.- s
is the alternative
Schedulerreference to use for observing events- os
is the OverflowStrategy to apply to the underlying buffer
- Definition Classes
- Observable
- See also
observeOn(Scheduler) for the version that does not take an
OverflowStrategyparameter.
-
final
def
observeOn(s: Scheduler): Observable[A]
Operator that specifies a different Scheduler, on which subscribers will observe events, instead of the default one.
Operator that specifies a different Scheduler, on which subscribers will observe events, instead of the default one.
An
Observablewith an appliedobserveOncall will forward events into a buffer that uses the specifiedSchedulerreference to cycle through events and to makeonNextcalls to downstream listeners.Example:
import monix.execution.Scheduler val io = Scheduler.io("my-io") source.map(_ + 1) .observeOn(io) .foreach(x => println(x))
In the above example the first
map(whatever comes before theobserveOncall) gets executed using the defaultScheduler(might execute on the current thread even), however theforeachthat's specified afterobserveOnwill get executed on the indicatedScheduler.NOTE: this operator does not guarantee that downstream listeners will actually use the specified
Schedulerto process events, because this depends on the rest of the pipeline. E.g. this will not work OK:source.observeOn(io).asyncBoundary(Unbounded)
This sample might not do what a user of
observeOnwould want. Indeed the implementation will use the providedioreference for callingonNext/onComplete/onErrorevents, however because of the following asynchronous boundary created the actual listeners will probably end up being execute on a differentScheduler.The underlying implementation uses a buffer to forward events. The OverflowStrategy being applied is the default one.
- s
is the alternative
Schedulerreference to use for observing events
- Definition Classes
- Observable
- See also
observeOn(Scheduler, OverflowStrategy) for the version that allows customizing the OverflowStrategy being used by the underlying buffer.
-
final
def
onCancelTriggerError: Observable[A]
If the connection is cancelled then trigger a
CancellationException.If the connection is cancelled then trigger a
CancellationException.A connection can be cancelled with the help of the Cancelable returned on subscribe.
Because the cancellation is effectively concurrent with the signals the Observer receives and because we need to uphold the contract, this operator will effectively synchronize access to onNext, onComplete and onError. It will also watch out for asynchronous Stop events.
In other words, this operator does heavy synchronization, can prove to be inefficient and you should avoid using it because the signaled error can interfere with functionality from other operators that use cancellation internally and cancellation in general is a side-effecting operation that should be avoided, unless it's necessary.
- Definition Classes
- Observable
-
def
onComplete(): Unit
- Definition Classes
- PublishSubject → Observer
-
def
onError(ex: Throwable): Unit
- Definition Classes
- PublishSubject → Observer
-
final
def
onErrorFallbackTo[B >: A](that: Observable[B]): Observable[B]
Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events continues with the specified backup sequence.Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events continues with the specified backup sequence.The created Observable mirrors the behavior of the source in case the source does not end with an error.
NOTE that compared with
onErrorResumeNextfrom Rx.NET, the streaming is not resumed in case the source is terminated normally with anonComplete.- that
is a backup sequence that's being subscribed in case the source terminates with an error.
- Definition Classes
- Observable
-
final
def
onErrorHandle[B >: A](f: (Throwable) ⇒ B): Observable[B]
Returns an observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events fallbacks to an observable emitting a single element generated by the backup function.Returns an observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events fallbacks to an observable emitting a single element generated by the backup function.See onErrorRecover for the version that takes a partial function as a parameter.
- f
- a function that matches errors with a backup element that is emitted when the source throws an error.
- Definition Classes
- Observable
-
final
def
onErrorHandleWith[B >: A](f: (Throwable) ⇒ Observable[B]): Observable[B]
Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events continues with the specified backup sequence generated by the given function.Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events continues with the specified backup sequence generated by the given function.See onErrorRecoverWith for the version that takes a partial function as a parameter.
- f
is a function that matches errors with a backup throwable that is subscribed when the source throws an error.
- Definition Classes
- Observable
-
final
def
onErrorRecover[B >: A](pf: PartialFunction[Throwable, B]): Observable[B]
Returns an observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events fallbacks to an observable emitting a single element generated by the backup function.Returns an observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events fallbacks to an observable emitting a single element generated by the backup function.The created Observable mirrors the behavior of the source in case the source does not end with an error or if the thrown
Throwableis not matched.See onErrorHandle for the version that takes a total function as a parameter.
- pf
- a function that matches errors with a backup element that is emitted when the source throws an error.
- Definition Classes
- Observable
-
final
def
onErrorRecoverWith[B >: A](pf: PartialFunction[Throwable, Observable[B]]): Observable[B]
Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events continues with the specified backup sequence generated by the given function.Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case the streaming of events continues with the specified backup sequence generated by the given function.The created Observable mirrors the behavior of the source in case the source does not end with an error or if the thrown
Throwableis not matched.See onErrorHandleWith for the version that takes a total function as a parameter.
- pf
is a function that matches errors with a backup throwable that is subscribed when the source throws an error.
- Definition Classes
- Observable
-
final
def
onErrorRestart(maxRetries: Long): Observable[A]
Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case it tries subscribing to the source again in the hope that it will complete without an error.Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case it tries subscribing to the source again in the hope that it will complete without an error.The number of retries is limited by the specified
maxRetriesparameter, so for an Observable that always ends in error the total number of subscriptions that will eventually happen ismaxRetries + 1.- Definition Classes
- Observable
-
final
def
onErrorRestartIf(p: (Throwable) ⇒ Boolean): Observable[A]
Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case it tries subscribing to the source again in the hope that it will complete without an error.Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case it tries subscribing to the source again in the hope that it will complete without an error.The given predicate establishes if the subscription should be retried or not.
- Definition Classes
- Observable
-
final
def
onErrorRestartUnlimited: Observable[A]
Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case it tries subscribing to the source again in the hope that it will complete without an error.Returns an Observable that mirrors the behavior of the source, unless the source is terminated with an
onError, in which case it tries subscribing to the source again in the hope that it will complete without an error.NOTE: The number of retries is unlimited, so something like
Observable.error(new RuntimeException).onErrorRestartUnlimitedwill loop forever.- Definition Classes
- Observable
-
def
onNext(elem: A): Future[Ack]
- Definition Classes
- PublishSubject → Observer
-
final
def
pipeThrough[I >: A, B](pipe: Pipe[I, B]): Observable[B]
Given a Pipe, transform the source observable with it.
Given a Pipe, transform the source observable with it.
- Definition Classes
- Observable
-
final
def
pipeThroughSelector[S >: A, B, R](pipe: Pipe[S, B], f: (Observable[B]) ⇒ Observable[R]): Observable[R]
Returns an observable that emits the results of invoking a specified selector on items emitted by a ConnectableObservable, which shares a single subscription to the underlying sequence.
Returns an observable that emits the results of invoking a specified selector on items emitted by a ConnectableObservable, which shares a single subscription to the underlying sequence.
- pipe
is the Pipe used to transform the source into a multicast (hot) observable that can be shared in the selector function
- f
is a selector function that can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Observers to the given source will receive all notifications of the source from the time of the subscription forward.
- Definition Classes
- Observable
-
final
def
publish(implicit s: Scheduler): ConnectableObservable[A]
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e.
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e. whose source is shared by all observers). The underlying subject used is a PublishSubject.
- Definition Classes
- Observable
-
final
def
publishLast(implicit s: Scheduler): ConnectableObservable[A]
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e.
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e. whose source is shared by all observers). The underlying subject used is a AsyncSubject.
- Definition Classes
- Observable
-
final
def
publishSelector[R](f: (Observable[A]) ⇒ Observable[R]): Observable[R]
Returns an observable that emits the results of invoking a specified selector on items emitted by a ConnectableObservable, which shares a single subscription to the underlying sequence.
Returns an observable that emits the results of invoking a specified selector on items emitted by a ConnectableObservable, which shares a single subscription to the underlying sequence.
- f
is a selector function that can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Observers to the given source will receive all notifications of the source from the time of the subscription forward.
- Definition Classes
- Observable
-
final
def
reduce[B >: A](op: (B, B) ⇒ B): Observable[B]
Applies a binary operator to a start value and all elements of this Observable, going left to right and returns a new Observable that emits only one item before
onComplete.Applies a binary operator to a start value and all elements of this Observable, going left to right and returns a new Observable that emits only one item before
onComplete.- Definition Classes
- Observable
-
final
def
repeat: Observable[A]
Repeats the items emitted by the source continuously.
Repeats the items emitted by the source continuously. It caches the generated items until
onCompleteand repeats them forever.It terminates either on error or if the source is empty.
- Definition Classes
- Observable
-
final
def
replay(bufferSize: Int)(implicit s: Scheduler): ConnectableObservable[A]
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e.
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e. whose source is shared by all observers). The underlying subject used is a ReplaySubject.
- bufferSize
is the size of the buffer limiting the number of items that can be replayed (on overflow the head starts being dropped)
- Definition Classes
- Observable
-
final
def
replay(implicit s: Scheduler): ConnectableObservable[A]
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e.
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e. whose source is shared by all observers). The underlying subject used is a ReplaySubject.
- Definition Classes
- Observable
-
final
def
restartUntil(p: (A) ⇒ Boolean): Observable[A]
Keeps restarting / resubscribing the source until the predicate returns
truefor the the first emitted element, after which it starts mirroring the source.Keeps restarting / resubscribing the source until the predicate returns
truefor the the first emitted element, after which it starts mirroring the source.- Definition Classes
- Observable
-
final
def
runAsyncGetFirst(implicit s: Scheduler): CancelableFuture[Option[A]]
Creates a new CancelableFuture that upon execution will signal the first generated element of the source observable.
Creates a new CancelableFuture that upon execution will signal the first generated element of the source observable. Returns an
Optionbecause the source can be empty.- Definition Classes
- Observable
-
final
def
runAsyncGetLast(implicit s: Scheduler): CancelableFuture[Option[A]]
Creates a new CancelableFuture that upon execution will signal the last generated element of the source observable.
Creates a new CancelableFuture that upon execution will signal the last generated element of the source observable. Returns an
Optionbecause the source can be empty.- Definition Classes
- Observable
-
final
def
sample(period: FiniteDuration): Observable[A]
Emit the most recent items emitted by the source within periodic time intervals.
Emit the most recent items emitted by the source within periodic time intervals.
Use the
sampleoperator to periodically look at an observable to see what item it has most recently emitted since the previous sampling. Note that if the source observable has emitted no items since the last time it was sampled, the observable that results from thesampleoperator will emit no item for that sampling period.- period
the timespan at which sampling occurs
- Definition Classes
- Observable
- See also
sampleRepeated for repeating the last value on silence
sampleBy for fine control
-
final
def
sampleBy[B](sampler: Observable[B]): Observable[A]
Returns an observable that, when the specified sampler emits an item or completes, emits the most recently emitted item (if any) emitted by the source since the previous emission from the sampler.
Returns an observable that, when the specified sampler emits an item or completes, emits the most recently emitted item (if any) emitted by the source since the previous emission from the sampler.
Use the
sampleByoperator to periodically look at an observable to see what item it has most recently emitted since the previous sampling. Note that if the source observable has emitted no items since the last time it was sampled, the observable that results from thesampleByoperator will emit no item.- sampler
- the observable to use for sampling the source
- Definition Classes
- Observable
- See also
sampleRepeatedBy for repeating the last value on silence
sample for periodic sampling
-
final
def
sampleRepeated(period: FiniteDuration): Observable[A]
Emit the most recent items emitted by an observable within periodic time intervals.
Emit the most recent items emitted by an observable within periodic time intervals. If no new value has been emitted since the last time it was sampled, it signals the last emitted value anyway.
- period
the timespan at which sampling occurs
- Definition Classes
- Observable
- See also
sampleRepeatedBy for fine control
sample for a variant that doesn't repeat the last value on silence
-
final
def
sampleRepeatedBy[B](sampler: Observable[B]): Observable[A]
Returns an observable that, when the specified sampler observable emits an item or completes, emits the most recently emitted item (if any) emitted by the source Observable since the previous emission from the sampler observable.
Returns an observable that, when the specified sampler observable emits an item or completes, emits the most recently emitted item (if any) emitted by the source Observable since the previous emission from the sampler observable. If no new value has been emitted since the last time it was sampled, it signals the last emitted value anyway.
- sampler
- the Observable to use for sampling the source Observable
- Definition Classes
- Observable
- See also
sampleRepeated for a periodic sampling
sampleBy for a variant that doesn't repeat the last value on silence
-
final
def
scan[S](seed: ⇒ S)(op: (S, A) ⇒ S): Observable[S]
Applies a binary operator to a start value and all elements of this Observable, going left to right and returns a new Observable that emits on each step the result of the applied function.
Applies a binary operator to a start value and all elements of this Observable, going left to right and returns a new Observable that emits on each step the result of the applied function.
Similar to foldLeftF, but emits the state on each step. Useful for modeling finite state machines.
- Definition Classes
- Observable
-
final
def
scanEval[F[_], S](seed: F[S])(op: (S, A) ⇒ F[S])(implicit F: Effect[F]): Observable[S]
Applies a binary operator to a start value and all elements of this stream, going left to right and returns a new stream that emits on each step the result of the applied function.
Applies a binary operator to a start value and all elements of this stream, going left to right and returns a new stream that emits on each step the result of the applied function.
Similar with scan, but this can suspend and evaluate side effects with an
F[_]data type that implements thecats.effect.Effecttype class, thus allowing for lazy or asynchronous data processing.Similar to foldLeftF and foldWhileLeftF, but emits the state on each step. Useful for modeling finite state machines.
Example showing how state can be evolved and acted upon:
// Using cats.effect.IO for evaluating our side effects import cats.effect.IO sealed trait State[+A] { def count: Int } case object Init extends State[Nothing] { def count = 0 } case class Current[A](current: Option[A], count: Int) extends State[A] case class Person(id: Int, name: String) // Initial state val seed = IO.pure(Init : State[Person]) val scanned = source.scanEval(seed) { (state, id) => requestPersonDetails(id).map { person => state match { case Init => Current(person, 1) case Current(_, count) => Current(person, count + 1) } } } scanned .takeWhile(_.count < 10) .collect { case Current(a, _) => a }
- seed
is the initial state
- op
is the function that evolves the current state
- F
is the
cats.effect.Effecttype class implementation for typeF, which controls the evaluation.Fcan be a data type such as monix.eval.Task orcats.effect.IO, which implementEffect.- returns
a new observable that emits all intermediate states being resulted from applying the given function
- Definition Classes
- Observable
- See also
scan for the synchronous, non-lazy version, or scanTask for the Task-specialized version.
-
final
def
scanMap[B](f: (A) ⇒ B)(implicit B: Monoid[B]): Observable[B]
Given a mapping function that returns a
Btype for which we have a cats.Monoid instance, returns a new stream that folds the incoming elements of the sources using the providedMonoid[B].combine, with the initial seed being theMonoid[B].emptyvalue, emitting the generated values at each step.Given a mapping function that returns a
Btype for which we have a cats.Monoid instance, returns a new stream that folds the incoming elements of the sources using the providedMonoid[B].combine, with the initial seed being theMonoid[B].emptyvalue, emitting the generated values at each step.Equivalent with scan applied with the given cats.Monoid, so given our
fmapping function returns aB, this law holds:val B = implicitly[Monoid[B]] stream.scanMap(f) <-> stream.scan(B.empty)(B.combine)
Example:
// Yields 2, 6, 12, 20, 30, 42 Observable(1, 2, 3, 4, 5, 6).scanMap(x => x * 2)
- f
is the mapping function applied to every incoming element of this
Observablebefore folding usingMonoid[B].combine- returns
a new
Observablethat emits all intermediate states being resulted from applyingMonoid[B].combinefunction
- Definition Classes
- Observable
-
final
def
scanTask[S](seed: Task[S])(op: (S, A) ⇒ Task[S]): Observable[S]
Applies a binary operator to a start value and all elements of this stream, going left to right and returns a new stream that emits on each step the result of the applied function.
Applies a binary operator to a start value and all elements of this stream, going left to right and returns a new stream that emits on each step the result of the applied function.
Similar with scan, but this can suspend and evaluate side effects with Task, thus allowing for asynchronous data processing.
Similar to foldLeftF and foldWhileLeftF, but emits the state on each step. Useful for modeling finite state machines.
Example showing how state can be evolved and acted upon:
sealed trait State[+A] { def count: Int } case object Init extends State[Nothing] { def count = 0 } case class Current[A](current: Option[A], count: Int) extends State[A] case class Person(id: Int, name: String) // Initial state val seed = Task.now(Init : State[Person]) val scanned = source.scanTask(seed) { (state, id) => requestPersonDetails(id).map { person => state match { case Init => Current(person, 1) case Current(_, count) => Current(person, count + 1) } } } scanned .takeWhile(_.count < 10) .collect { case Current(a, _) => a }
- seed
is the initial state
- op
is the function that evolves the current state
- returns
a new observable that emits all intermediate states being resulted from applying the given function
- Definition Classes
- Observable
- See also
scan for the version that does not require using
Taskin the provided operator
-
final
def
share(implicit s: Scheduler): Observable[A]
Returns a new Observable that multi-casts (shares) the original Observable.
Returns a new Observable that multi-casts (shares) the original Observable.
- Definition Classes
- Observable
-
def
size: Int
Returns the number of connected subscribers.
Returns the number of connected subscribers.
Note this might be an expensive operation.
Should be used for debugging purposes or for collecting metrics, but don't overuse because the accessed state is a volatile read, and counting subscribers might have linear complexity, depending on the underlying data-structure.
- Definition Classes
- PublishSubject → Subject
-
final
def
startWith[B >: A](elems: Seq[B]): Observable[B]
Creates a new Observable that emits the given elements and then it also emits the events of the source (prepend operation).
Creates a new Observable that emits the given elements and then it also emits the events of the source (prepend operation).
- Definition Classes
- Observable
-
final
def
subscribe(nextFn: (A) ⇒ Future[Ack], errorFn: (Throwable) ⇒ Unit, completedFn: () ⇒ Unit)(implicit s: Scheduler): Cancelable
Subscribes to the stream.
Subscribes to the stream.
- returns
a subscription that can be used to cancel the streaming.
- Definition Classes
- Observable
- See also
consumeWith for another way of consuming observables
-
final
def
subscribe(nextFn: (A) ⇒ Future[Ack])(implicit s: Scheduler): Cancelable
Subscribes to the stream.
Subscribes to the stream.
- returns
a subscription that can be used to cancel the streaming.
- Definition Classes
- Observable
- See also
consumeWith for another way of consuming observables
-
final
def
subscribe()(implicit s: Scheduler): Cancelable
Subscribes to the stream.
Subscribes to the stream.
- returns
a subscription that can be used to cancel the streaming.
- Definition Classes
- Observable
- See also
consumeWith for another way of consuming observables
-
final
def
subscribe(nextFn: (A) ⇒ Future[Ack], errorFn: (Throwable) ⇒ Unit)(implicit s: Scheduler): Cancelable
Subscribes to the stream.
Subscribes to the stream.
- returns
a subscription that can be used to cancel the streaming.
- Definition Classes
- Observable
- See also
consumeWith for another way of consuming observables
-
final
def
subscribe(subscriber: Subscriber[A]): Cancelable
Subscribes to the stream.
Subscribes to the stream.
- returns
a subscription that can be used to cancel the streaming.
- Definition Classes
- Observable
- See also
consumeWith for another way of consuming observables
-
final
def
subscribe(observer: Observer[A])(implicit s: Scheduler): Cancelable
Subscribes to the stream.
Subscribes to the stream.
- returns
a subscription that can be used to cancel the streaming.
- Definition Classes
- Observable
- See also
consumeWith for another way of consuming observables
-
final
def
subscribeOn(scheduler: Scheduler): Observable[A]
Returns a new Observable that uses the specified
Schedulerfor initiating the subscription.Returns a new Observable that uses the specified
Schedulerfor initiating the subscription.- Definition Classes
- Observable
-
final
def
sumF[AA >: A](implicit A: Numeric[AA]): Observable[AA]
Given a source that emits numeric values, the
sumoperator sums up all values and at onComplete it emits the total.Given a source that emits numeric values, the
sumoperator sums up all values and at onComplete it emits the total.- Definition Classes
- Observable
-
final
def
sumL[B >: A](implicit B: Numeric[B]): Task[B]
Given a source that emits numeric values, the
sumoperator sums up all values and returns the result.Given a source that emits numeric values, the
sumoperator sums up all values and returns the result.- Definition Classes
- Observable
-
final
def
switch[B](implicit ev: <:<[A, Observable[B]]): Observable[B]
Convert an observable that emits observables into a single observable that emits the items emitted by the most-recently-emitted of those observables.
Convert an observable that emits observables into a single observable that emits the items emitted by the most-recently-emitted of those observables.
- Definition Classes
- Observable
-
final
def
switchIfEmpty[B >: A](backup: Observable[B]): Observable[B]
In case the source is empty, switch to the given backup.
In case the source is empty, switch to the given backup.
- Definition Classes
- Observable
-
final
def
switchMap[B](f: (A) ⇒ Observable[B]): Observable[B]
Returns a new observable that emits the items emitted by the observable most recently generated by the mapping function.
Returns a new observable that emits the items emitted by the observable most recently generated by the mapping function.
- Definition Classes
- Observable
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
final
def
tail: Observable[A]
Drops the first element of the source observable, emitting the rest.
Drops the first element of the source observable, emitting the rest.
- Definition Classes
- Observable
-
final
def
take(n: Long): Observable[A]
Selects the first
nelements (from the start).Selects the first
nelements (from the start).- n
the number of elements to take
- returns
a new Observable that emits only the first
nelements from the source
- Definition Classes
- Observable
-
final
def
takeByTimespan(timespan: FiniteDuration): Observable[A]
Creates a new Observable that emits the events of the source, only for the specified
timestamp, after which it completes.Creates a new Observable that emits the events of the source, only for the specified
timestamp, after which it completes.- timespan
the window of time during which the new Observable is allowed to emit the events of the source
- Definition Classes
- Observable
-
final
def
takeEveryNth(n: Int): Observable[A]
Creates a new Observable that emits every n-th event from the source, dropping intermediary events.
Creates a new Observable that emits every n-th event from the source, dropping intermediary events.
- Definition Classes
- Observable
-
final
def
takeLast(n: Int): Observable[A]
Creates a new observable that only emits the last
nelements emitted by the source.Creates a new observable that only emits the last
nelements emitted by the source.In case the source triggers an error, then the underlying buffer gets dropped and the error gets emitted immediately.
- Definition Classes
- Observable
-
final
def
takeUntil(trigger: Observable[Any]): Observable[A]
Creates a new observable that mirrors the source until the given
triggeremits either an element oronComplete, after which it is completed.Creates a new observable that mirrors the source until the given
triggeremits either an element oronComplete, after which it is completed.The resulting observable is completed as soon as
triggeremits either anonNextoronComplete. Iftriggeremits anonError, then the resulting observable is also completed with error.- trigger
is an observable that will cancel the streaming as soon as it emits an event
- Definition Classes
- Observable
-
final
def
takeWhile(p: (A) ⇒ Boolean): Observable[A]
Takes longest prefix of elements that satisfy the given predicate and returns a new Observable that emits those elements.
Takes longest prefix of elements that satisfy the given predicate and returns a new Observable that emits those elements.
- Definition Classes
- Observable
-
final
def
takeWhileNotCanceled(c: BooleanCancelable): Observable[A]
Takes longest prefix of elements while given BooleanCancelable is not canceled and returns a new Observable that emits those elements.
Takes longest prefix of elements while given BooleanCancelable is not canceled and returns a new Observable that emits those elements.
- Definition Classes
- Observable
-
final
def
throttleFirst(interval: FiniteDuration): Observable[A]
Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.
Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.
This differs from Observable!.throttleLast in that this only tracks passage of time whereas
throttleLastticks at scheduled intervals.- interval
time to wait before emitting another item after emitting the last item
- Definition Classes
- Observable
-
final
def
throttleLast(period: FiniteDuration): Observable[A]
Emit the most recent items emitted by the source within periodic time intervals.
Emit the most recent items emitted by the source within periodic time intervals.
Alias for sample.
- period
duration of windows within which the last item emitted by the source Observable will be emitted
- Definition Classes
- Observable
-
final
def
throttleWithTimeout(timeout: FiniteDuration): Observable[A]
Only emit an item from an observable if a particular timespan has passed without it emitting another item.
Only emit an item from an observable if a particular timespan has passed without it emitting another item.
Note: If the source observable keeps emitting items more frequently than the length of the time window, then no items will be emitted by the resulting observable.
Alias for debounce.
- timeout
the length of the window of time that must pass after the emission of an item from the source observable in which that observable emits no items in order for the item to be emitted by the resulting observable
- Definition Classes
- Observable
- See also
echoOnce for a similar operator that also mirrors the source observable
-
final
def
timeoutOnSlowDownstream(timeout: FiniteDuration): Observable[A]
Returns an observable that mirrors the source but that will trigger a DownstreamTimeoutException in case the downstream subscriber takes more than the given timespan to process an
onNextmessage.Returns an observable that mirrors the source but that will trigger a DownstreamTimeoutException in case the downstream subscriber takes more than the given timespan to process an
onNextmessage.Note that this ignores the time it takes for the upstream to send
onNextmessages. For detecting slow producers see timeoutOnSlowUpstream.- timeout
maximum duration for
onNext.
- Definition Classes
- Observable
-
final
def
timeoutOnSlowUpstream(timeout: FiniteDuration): Observable[A]
Returns an observable that mirrors the source but applies a timeout for each emitted item by the upstream.
Returns an observable that mirrors the source but applies a timeout for each emitted item by the upstream. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resulting Observable terminates and notifies observers of a TimeoutException.
Note that this ignores the time it takes to process
onNext. If dealing with a slow consumer, see timeoutOnSlowDownstream.- timeout
maximum duration between emitted items before a timeout occurs (ignoring the time it takes to process
onNext)
- Definition Classes
- Observable
-
final
def
timeoutOnSlowUpstreamTo[B >: A](timeout: FiniteDuration, backup: Observable[B]): Observable[B]
Returns an observable that mirrors the source but applies a timeout for each emitted item by the upstream.
Returns an observable that mirrors the source but applies a timeout for each emitted item by the upstream. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the source is terminated and the downstream gets subscribed to the given backup.
Note that this ignores the time it takes to process
onNext. If dealing with a slow consumer, see timeoutOnSlowDownstream.- timeout
maximum duration between emitted items before a timeout occurs (ignoring the time it takes to process
onNext)- backup
is the alternative data source to subscribe to on timeout
- Definition Classes
- Observable
-
final
def
toListL: Task[List[A]]
Returns a
Taskthat upon evaluation will collect all items from the source in a ScalaListand return this list instead.Returns a
Taskthat upon evaluation will collect all items from the source in a ScalaListand return this list instead.WARNING: for infinite streams the process will eventually blow up with an out of memory error.
- Definition Classes
- Observable
-
final
def
toReactiveProcessor[U >: A](bufferSize: Int)(implicit s: Scheduler): Processor[A, U]
- Definition Classes
- Subject
-
final
def
toReactiveProcessor[U >: A](implicit s: Scheduler): Processor[A, U]
- Definition Classes
- Subject
-
final
def
toReactivePublisher[B >: A](implicit s: Scheduler): Publisher[B]
Converts this
Observableinto anorg.reactivestreams.Publisher.Converts this
Observableinto anorg.reactivestreams.Publisher.Meant for interoperability with other Reactive Streams implementations.
Usage sample:
import monix.eval.Task import monix.execution.rstreams.SingleAssignmentSubscription import org.reactivestreams.{Publisher, Subscriber, Subscription} def sum(source: Publisher[Int], requestSize: Int): Task[Long] = Task.create { (_, cb) => val sub = SingleAssignmentSubscription() source.subscribe(new Subscriber[Int] { private[this] var requested = 0L private[this] var sum = 0L def onSubscribe(s: Subscription): Unit = { sub := s requested = requestSize s.request(requestSize) } def onNext(t: Int): Unit = { sum += t if (requestSize != Long.MaxValue) requested -= 1 if (requested <= 0) { requested = requestSize sub.request(request) } } def onError(t: Throwable): Unit = cb.onError(t) def onComplete(): Unit = cb.onSuccess(sum) }) // Cancelable that can be used by Task sub } val pub = Observable(1, 2, 3, 4).toReactivePublisher // Yields 10 sum(pub, requestSize = 128)
See the Reactive Streams protocol for details.
- Definition Classes
- Observable
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
uncancelable: Observable[A]
Makes the source
Observableuninterruptible such that acancelsignal has no effect.Makes the source
Observableuninterruptible such that acancelsignal has no effect.val cancelable = Observable .eval(println("Hello!")) .delayExecution(10.seconds) .subscribe() // No longer works cancelable.cancel() // After 10 seconds //=> Hello!
- Definition Classes
- Observable
-
final
def
unsafeMulticast[B >: A, R](processor: Subject[B, R])(implicit s: Scheduler): ConnectableObservable[R]
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e.
Converts this observable into a multicast observable, useful for turning a cold observable into a hot one (i.e. whose source is shared by all observers).
This operator is unsafe because
Subjectobjects are stateful and have to obey theObservercontract, meaning that they shouldn't be subscribed multiple times, so they are error prone. Only use if you know what you're doing, otherwise prefer the safe multicast operator.- Definition Classes
- Observable
-
def
unsafeSubscribeFn(subscriber: Subscriber[A]): Cancelable
Characteristic function for an
Observableinstance, that creates the subscription and that eventually starts the streaming of events to the given Observer, to be provided by observable implementations.Characteristic function for an
Observableinstance, that creates the subscription and that eventually starts the streaming of events to the given Observer, to be provided by observable implementations.WARNING: This function is "unsafe" to call because it does not protect the calls to the given Observer implementation in regards to unexpected exceptions that violate the contract, therefore the given instance must respect its contract and not throw any exceptions when the observable calls
onNext,onCompleteandonError. If it does, then the behavior is undefined.Prefer normal subscribe when consuming a stream, these unsafe subscription methods being useful when building operators and for testing purposes.
- Definition Classes
- PublishSubject → Observable
- Annotations
- @tailrec()
-
final
def
unsafeSubscribeFn(observer: Observer[A])(implicit s: Scheduler): Cancelable
Given an observer and a scheduler for managing async boundaries, subscribes to this observable for events.
Given an observer and a scheduler for managing async boundaries, subscribes to this observable for events.
Helper for calling the abstract method.
WARNING: this method is unsafe for calling directly because subscriber instances aren't automatically wrapped in SafeSubscriber.
Prefer normal subscribe when consuming a stream, these unsafe subscription methods being useful when building operators and for testing purposes.
- Definition Classes
- Observable
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
whileBusyBuffer[B >: A](overflowStrategy: Synchronous[B]): Observable[B]
While the destination observer is busy, buffers events, applying the given overflowStrategy.
While the destination observer is busy, buffers events, applying the given overflowStrategy.
- overflowStrategy
- the overflow strategy used for buffering, which specifies what to do in case we're dealing with a slow consumer - should an unbounded buffer be used, should back-pressure be applied, should the pipeline drop newer or older events, should it drop the whole buffer? See OverflowStrategy for more details.
- Definition Classes
- Observable
-
final
def
whileBusyDropEvents: Observable[A]
While the destination observer is busy, drop the incoming events.
While the destination observer is busy, drop the incoming events.
- Definition Classes
- Observable
-
final
def
whileBusyDropEventsAndSignal[B >: A](onOverflow: (Long) ⇒ B): Observable[B]
While the destination observer is busy, drop the incoming events.
While the destination observer is busy, drop the incoming events. When the downstream recovers, we can signal a special event meant to inform the downstream observer how many events where dropped.
- onOverflow
- a function that is used for signaling a special event used to inform the consumers that an overflow event happened, function that receives the number of dropped events as a parameter (see OverflowStrategy.Evicted)
- Definition Classes
- Observable
-
final
def
withLatestFrom[B, R](other: Observable[B])(f: (A, B) ⇒ R): Observable[R]
Combines the elements emitted by the source with the latest element emitted by another observable.
Combines the elements emitted by the source with the latest element emitted by another observable.
Similar with
combineLatest, but only emits items when the single source emits an item (not when any of the Observables that are passed to the operator do, as combineLatest does).- other
is an observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
withLatestFrom2[B1, B2, R](o1: Observable[B1], o2: Observable[B2])(f: (A, B1, B2) ⇒ R): Observable[R]
Combines the elements emitted by the source with the latest elements emitted by two observables.
Combines the elements emitted by the source with the latest elements emitted by two observables.
Similar with
combineLatest, but only emits items when the single source emits an item (not when any of the Observables that are passed to the operator do, as combineLatest does).- o1
is the first observable that gets paired with the source
- o2
is the second observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
withLatestFrom3[B1, B2, B3, R](o1: Observable[B1], o2: Observable[B2], o3: Observable[B3])(f: (A, B1, B2, B3) ⇒ R): Observable[R]
Combines the elements emitted by the source with the latest elements emitted by three observables.
Combines the elements emitted by the source with the latest elements emitted by three observables.
Similar with
combineLatest, but only emits items when the single source emits an item (not when any of the Observables that are passed to the operator do, as combineLatest does).- o1
is the first observable that gets paired with the source
- o2
is the second observable that gets paired with the source
- o3
is the third observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
withLatestFrom4[B1, B2, B3, B4, R](o1: Observable[B1], o2: Observable[B2], o3: Observable[B3], o4: Observable[B4])(f: (A, B1, B2, B3, B4) ⇒ R): Observable[R]
Combines the elements emitted by the source with the latest elements emitted by four observables.
Combines the elements emitted by the source with the latest elements emitted by four observables.
Similar with
combineLatest, but only emits items when the single source emits an item (not when any of the Observables that are passed to the operator do, as combineLatest does).- o1
is the first observable that gets paired with the source
- o2
is the second observable that gets paired with the source
- o3
is the third observable that gets paired with the source
- o4
is the fourth observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
withLatestFrom5[B1, B2, B3, B4, B5, R](o1: Observable[B1], o2: Observable[B2], o3: Observable[B3], o4: Observable[B4], o5: Observable[B5])(f: (A, B1, B2, B3, B4, B5) ⇒ R): Observable[R]
Combines the elements emitted by the source with the latest elements emitted by five observables.
Combines the elements emitted by the source with the latest elements emitted by five observables.
Similar with
combineLatest, but only emits items when the single source emits an item (not when any of the Observables that are passed to the operator do, as combineLatest does).- o1
is the first observable that gets paired with the source
- o2
is the second observable that gets paired with the source
- o3
is the third observable that gets paired with the source
- o4
is the fourth observable that gets paired with the source
- o5
is the fifth observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
withLatestFrom6[B1, B2, B3, B4, B5, B6, R](o1: Observable[B1], o2: Observable[B2], o3: Observable[B3], o4: Observable[B4], o5: Observable[B5], o6: Observable[B6])(f: (A, B1, B2, B3, B4, B5, B6) ⇒ R): Observable[R]
Combines the elements emitted by the source with the latest elements emitted by six observables.
Combines the elements emitted by the source with the latest elements emitted by six observables.
Similar with
combineLatest, but only emits items when the single source emits an item (not when any of the Observables that are passed to the operator do, as combineLatest does).- o1
is the first observable that gets paired with the source
- o2
is the second observable that gets paired with the source
- o3
is the third observable that gets paired with the source
- o4
is the fourth observable that gets paired with the source
- o5
is the fifth observable that gets paired with the source
- o6
is the sixth observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
zip[B](other: Observable[B]): Observable[(A, B)]
Creates a new observable from this observable and another given observable by combining their items in pairs in a strict sequence.
Creates a new observable from this observable and another given observable by combining their items in pairs in a strict sequence.
So the first item emitted by the new observable will be the tuple of the first items emitted by each of the source observables; the second item emitted by the new observable will be a tuple with the second items emitted by each of those observables; and so forth.
See combineLatest for a more relaxed alternative that doesn't combine items in strict sequence.
- other
is an observable that gets paired with the source
- returns
a new observable sequence that emits the paired items of the source observables
- Definition Classes
- Observable
-
final
def
zipMap[B, R](other: Observable[B])(f: (A, B) ⇒ R): Observable[R]
Creates a new observable from this observable and another given observable by combining their items in pairs in a strict sequence.
Creates a new observable from this observable and another given observable by combining their items in pairs in a strict sequence.
So the first item emitted by the new observable will be the result of the function applied to the first item emitted by each of the source observables; the second item emitted by the new observable will be the result of the function applied to the second item emitted by each of those observables; and so forth.
See combineLatestMap for a more relaxed alternative that doesn't combine items in strict sequence.
- other
is an observable that gets paired with the source
- f
is a mapping function over the generated pairs
- Definition Classes
- Observable
-
final
def
zipWithIndex: Observable[(A, Long)]
Zips the emitted elements of the source with their indices.
Zips the emitted elements of the source with their indices.
- Definition Classes
- Observable